ApplicationComposer Maven Plugin


Even if it comes from test side of OpenEJB, ApplicationComposer is now a solution to develop microservices. Because of this evolution it now gets a maven plugin to be able to go further in the development pipeline.

Application Composer is a nice way to create a simple JavaEE application with OpenEJB
without worrying about the packaging – which doesn’t mean it is not powerful since you can
do JAX-RS, JAX-WS etc…

As a reminder a sample can look like:

@Default
@SimpleLog
@Classes(context = "/")
@EnableServices(jaxrs = true)
public class MyApp {
}

This is the most trivial example which will just deploy the jar containing MyApp class
enabling JAX-RS services on context root if they exist.

So, if we suppose our jar containers a User class (with a single name field)
and a resource returning a list of users:

@Path("user")
@Produces(MediaType.APPLICATION_JSON)
public class UserResource {
    @GET
    public List<User> list() {
        User user = new User();
        user.setName("default");
        return asList(user);
    }
}

Then running our main with the right dependencies (javaee-api + openejb-cxf-rs) will deploy the endpoint under http://localhost:4204/user.

Ok, but how do we run it?

The custom main

You can write a custom main using ApplicationComposers helper and just run your class like so:

public static void main(String[] args) {
    ApplicationComposers.run(MyApp.class, args);
}

ApplicationComposers main

You can reuse the existing main:

java -cp lib/*.jar org.apache.openejb.testing.ApplicationComposers com.company.MyApp ...

Maven

There is also an applicationcomposer-maven-plugin which allows you to:

– run an application
– zip a distribution

Here is a sample configuration for our application:

<plugin>
  <groupId>org.apache.tomee.maven</groupId>
  <artifactId>applicationcomposer-maven-plugin</artifactId>
  <version>7.0.0-SNAPSHOT</version>
  <configuration>
    <application>com.company.MyApp</application>
  </configuration>
</plugin>

Executing:

mvn applicationcomposer:run

The server will start and deploy your endpoint.

Executing:

mvn applicationcomposer:zip

The plugin will create a zip with this structure:

app-1.0-SNAPSHOT-applicationcomposer
    ├── bin
    │   ├── applicationcomposer
    │   └── environment
    ├── classes
    │   └── org
    └── lib
        └── *.jar

Lib folder contains the container libraries, bin the script to run the server and classes your binaries (the jar doesn’t need to be built).

Note : by adding a conf/ and a log/ folder you’ll get a standard openejb structure (not created by default).

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s