openxava / documentation / Getting started with OpenXava

Follow the instructions below to create and run your first OpenXava project using IntelliJ IDEA:

Creating a new project in IntelliJ

First, you have to create a new project using a Maven archetype from IntelliJ. To do this, choose the option File > New > Project...:

IntelliJ menu File > New > Project

Once in the dialog, choose the Maven Archetypes option within the Generators section:

New Project dialog with Maven Archetypes option

Then type the project name, invoicing, in the Name field:

Project name field with invoicing

Now it's time to choose the archetype. In the Catalog field select Maven Central and in the Archetype field type openxava so it shows you all the OpenXava archetypes. There choose openxava-archetype.

As the version, choose the latest available OpenXava version, which is currently 8.0.1.

Selecting openxava-archetype from Maven Central

To finish, go to the bottom of the dialog and open the Advanced Settings section, and in the GroupId field enter com.yourcompany, which is the value we will use in this course:

Advanced Settings with GroupId com.yourcompany

If everything went well, the dialog should look more or less like this:

Complete New Project dialog ready to create

Click the Create button to create the project.

Now your project is ready to start writing code:

Project structure ready to write code

Deleting the sample entity

Developing is very easy: you just have to add entities to make your application grow. Entities are added in the model package. Open the src/main/java folder and then the com.yourcompany.invoicing.model package. You will see that it contains a sample entity. Delete it (or ask your AI assistant to delete it):

Sample entity in model package to delete

Creating your first entity

If you use an AI assistant, see the next section.

Now we can add our own entities. We'll start with a simplified version of Customer with only number and name.

In the src/main/java folder select the com.yourcompany.invoicing.model package and right-click to choose New > Java Class:

Context menu New > Java Class

Then type Customer as the class name and press ENTER:

New Java Class dialog with Customer name

Note that the C of Customer is uppercase. This is very important: all Java classes start with an uppercase letter.

The initial code that IntelliJ provides for Customer is very simple:

package com.yourcompany.invoicing.model;
 
public class Customer {
}

Now, you have to fill in this class to turn it into an entity suitable for OpenXava. You only need to add the @Entity annotation and the number and name properties:

package com.yourcompany.invoicing.model;
 
import jakarta.persistence.*;
import org.openxava.annotations.*;
import lombok.*;
 
@Entity  // This marks the Customer class as an entity
@Getter @Setter // This makes all fields below publicly accessible
public class Customer {
 
    @Id  // The number property is the key property. Keys are required by default
    @Column(length=6)  // The column length is used at the UI level and the DB level
    int number;
 
    @Column(length=50)  // The column length is used at the UI level and the DB level
    @Required  // A validation error will be shown if the name property is left empty
    String name;
 
}

With this you have enough code (just one class) to run your application.

Or create your first entity with an AI assistant

If you use an AI coding assistant, such as GitHub Copilot, Cursor, Claude Code, Devin, Codex or JetBrains Junie, you don't need to write the above code yourself. Just open your project with your assistant and ask it to do the work, for example with this prompt:

Create a Customer entity with number as a numeric key and name

The assistant will generate code very similar to the one above. Your OpenXava project already includes an AGENTS.md file that teaches AI assistants the OpenXava conventions (more info).

Throughout the course, after each piece of code you will find an AI prompt box with a prompt that generates similar code. This way you can follow the course by writing the code yourself or by asking your AI assistant to write it.

Running the application

Open the com.yourcompany.invoicing package, right-click on the InvoicingApplication class and choose Run 'InvoicingApplication.main()':

Run InvoicingApplication.main() context menu option

Wait until the console shows a message saying "Started InvoicingApplication", like this:

Console showing Started InvoicingApplication message

Your application is now running. To see it, open your favorite browser (Chrome, Firefox, Edge or Safari) and go to the following URL:

    http://localhost:8080/invoicing

You are seeing your application running for the first time. To start, click on the Sign in button:

Application home page with Sign in button

Now, enter admin/admin and click on Sign in:

Sign In page

Then a list of modules will be shown on the left side. Choose Customers:

Module list showing Customers option

Use the Customers module to create new customers: just enter the number and name and press Save.

Customers module with data entry form

Click on List to see the customers you have created. Congratulations, you have your first OpenXava application running.

Modifying the application

From now on, developing with OpenXava is very easy. Simply write a class and you can see the result in the browser. Let's create an entity for Product.

Select the com.yourcompany.invoicing.model package and right-click to choose New > Java Class:

Context menu New > Java Class

Then type Product as the class name and press ENTER:

New Java Class dialog with Product name

Write the following code for Product:

package com.yourcompany.invoicing.model;
 
import jakarta.persistence.*;
import org.openxava.annotations.*;
import lombok.*;
 
@Entity @Getter @Setter
public class Product {
 
    @Id @Column(length=9)
    int number;
 
    @Column(length=50) @Required
    String description;
 
}
AI prompt
Create a Product entity with number and description

Now, click the Rerun button, which is the green button at the top of the IDE. This stops the application and restarts it:

Rerun button in IntelliJ toolbar

To see your new entity in action, open your browser and go to this URL:

    http://localhost:8080/invoicing/modules/Product

After signing in with admin/admin you'll get:

Product module running in browser

Yes, you have a new module running, and just by writing a simple class. Now you can concentrate on growing your application.

Any problem?

Congratulations! You have created your first OpenXava application. If not, or if you have had any problems with the example above, ask in the forum:

    Ask in the forum

We'll help you overcome any difficulty.

Next steps

This getting started guide is lesson 1 of a complete OpenXava course. This course is meant to teach you how to develop enterprise applications with OpenXava, as well as other Java-related technologies, tools and frameworks. Together we will develop a complete application step by step from scratch. The application chosen is a small invoicing application with invoices, customers, products and so on. This application is just a brief way to learn some typical cases in business applications. You can apply everything you learn with the invoicing application to any other business application of any other domain.

This is the content of the course:

Do you want to use another IDE? Do you want to use MySQL, PostgreSQL, Oracle, Microsoft SQL Server, AS/400, Informix, Db2 or Firebird? Do you want a detailed reference guide? Look at the OpenXava documentation, which includes this and much more.

Are you ready? Go to Lesson 2