OpenEJB 5 + Groovy = service done fast!


If you read the previous post I wrote about ApplicationComposers run method you surely wonder what a service could look like using groovy and @Grab to resolve maven dependencies?

Here is a quick post showing it:

import org.apache.openejb.testing.ApplicationComposers
import org.apache.openejb.testing.Classes
import org.apache.openejb.testing.EnableServices
import org.apache.openejb.testing.SimpleLog

import javax.ws.rs.GET
import javax.ws.rs.Path

@Grab("org.apache.openejb:javaee-api:7.0-SNAPSHOT")
@Grab("org.apache.openejb:openejb-cxf-rs:5.0.0-SNAPSHOT")

@Path("hi")
class Hi {
    @GET
    String hi() {
        "Hi"
    }
}

@SimpleLog
@EnableServices("jaxrs")
@Classes(Hi.class)
class Run {
}

ApplicationComposers.run(Run.class);

And that’s it,just hit run and you get your service deployed!

Just a little note about groovy: depending the distribution/setup of groovy you use to run it you can maybe desire remove servlet-api which is in groovy binary 2.4 distribution in 2.x version (OpenEJB 5 uses 3.1).
Another note about dependencies: at the moment openejb/javaee-api dependencies are on apache snapshot repository, if you don’t have them locally you can desire to configure grape to resolve them correctly.

Have fun with Groovy and OpenEJB microservices!

Advertisements

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 )

Google+ photo

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

Connecting to %s