Packaging your Roo project

If you are using Roo only to create the persistence layer of your enterprise application, then you may want to package your Roo project as a JAR file and use it. This recipe shows how you can package your Roo project and how Roo ensures that your packaged JAR file is independent of Roo-specific annotations and AspectJ ITDs.

Getting ready

Exit the Roo shell and delete the contents of the C: oo-cookbookch02-recipes directory.

Execute the ch02_jsr303_fields.roo script. It creates a flight-app Roo project and sets up Hibernate as persistence provider using the persistence setup command. The script also creates a Flight entity, which has FlightKey as its composite primary key class, and adds fields to the Flight and FlightKey classes. If you are using a different database than MySQL or your connection settings are different from what is specified in the script, then modify the script accordingly.

Start the Roo shell from the C: oo-cookbookch02-recipes directory.

How to do it...

To package your Roo project into a JAR file, execute the perform package command from the Roo shell:

roo> perform package

[INFO] ---------------------------------------------------------
[INFO] Building flight-app 0.1.0.BUILD-SNAPSHOT
[INFO] ---------------------------------------------------------
...
[INFO] --- aspectj-maven-plugin:1.2:compile (default) @ flight-app ---
...
[INFO] --- aspectj-maven-plugin:1.2:test-compile (default) @ flight-app ---
...
[INFO] Building jar: ...	argetflight-app-0.1.0.BUILD-SNAPSHOT.jar
[INFO] --------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------

How it works...

The perform package command packages the Roo project using maven. Alternatively, you can also use the mvn package command of maven to package the Roo project. It is important to note that when using the perform package command, tests defined in the Roo project are not executed.

The output from executing perform package shows that AspectJ compiler Maven Plugin is used to compile the main and test Java classes of the flight-app project. The compile goal of AspectJ compiler Maven Plugin weaves AspectJ ITDs and aspects defined in the spring-aspects.jar file into the main Java classes of the project. The test-compile goal weaves AspectJ ITDs and aspects defined in the spring-aspects.jar file into the test classes of the project.

The perform package command creates the flight-app project's JAR file in the target directory.

The following figure shows an example of how Flight.class is created by the AspectJ compiler Maven Plugin by weaving AspectJ ITDs that apply to the Flight.java class:

How it works...

The figure shows that AspectJ compiler Maven Plugin weaves Flight_Roo_Configurable.aj, Flight_Roo_Entity.aj, Flight_Roo_JavaBean.aj, and Flight_Roo_ToString.aj AspectJ ITDs into Flight.java to create Flight.class.

There's more...

To verify that your generated class file contains declarations from corresponding AspectJ ITDs, you can also use the javap command. The javap command examines a .class file and outputs the attributes, methods, and constructors that form part of the class.

To use javap, you need to first set the PATH environment variable to point to the bin directory of your Java SE installation, as shown here:

C:> set PATH=%PATH%;C:Program FilesJavajdk1.6.0_23in

Now, go to the directory which contains your Roo project (ch02-recipes in our case) and execute the javap command to view the details of the compiled Flight class, as shown here:

C:
oo-cookbookch02-recipes> javap -classpath targetclasses sample.roo.flightapp.domain.Flight

public class sample.roo.flightapp.domain.Flight ...
{
  transient javax.persistence.EntityManager entityManager;
  ...  
  public void clear();
  public static long countFlights();
  public static final javax.persistence.EntityManager 
    entityManager();
  public static java.util.List findAllFlights();
  ...
  public void flush();
  public java.lang.String getCreatedBy();
  public java.util.Date getCreatedDate();
  public java.lang.String getDestination();
  public sample.roo.flightapp.domain.FlightKey getId();
  public java.lang.String getModifiedBy();
  public java.util.Date getModifiedDate();
  public java.lang.Integer getNumOfSeats();
  public java.lang.String getOrigin();
  public java.lang.Integer getVersion();
  public sample.roo.flightapp.domain.Flight merge();
  public void persist();
  public void remove();
  ...
}

The output shows that methods defined in AspectJ ITDs are now part of the compiled Flight class file.

See also

  • Refer to the Creating integration tests for persistent entities recipe to see Spring Roo's support for auto-generation of integration tests for JPA entities.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.128.145