开发者

include model libraries in appclient jar

I'm deploying an ear with an EJB onto glassfish 3.1 which I want to call using the appclient script. The EJB has a method with as parameter a model object which is defined in a separate library.

If I want to use the appclient script I have a Main class with a main method which calls the EJB. This is also put into a separate jar which is also deployed on开发者_运维技巧to glassfish.

As the model object is located in a separate library I need it in the client jar but also in the EJB. So I need to reference it somehow in the client jar.

The client jar is a jar (duh) so I cannot add other jars. The Java EE 6 docs say that I should create an ear with the libs but if I do that it doesn't deploy because an ear needs at least an ejb or web module and my client lib has neither.

The solution I found is using the assembly plugin/jar-with-dependencies. This plugin creates a new jar which contains all classes of all dependencies.

This solution works but I'm wondering if this is the way to go or I'm missing something obvious because I cannot imagine this is required. EJB's usually have model objects as parameters so this situation will happen a lot.

So my question is: is there a way to tell glassfish to reference the shared libraries between the app client jar and the ejb jar.


The way I do this is like this:

  • Separate Maven project with the model. In my case that's a bunch of simple POJOs with JPA and JAX-B annotations, some constants, etc. In Maven, I define this as an OSGi bundle, by specifying <packaging>bundle</packaging>. I call this project MyAppInterface.
  • Separate Maven projects for other elements that need to deal with the model. In my case, I have one Java EE application with EJBs, Database facade, REST servlet; I have an Integration-Test project which only does tests; a GWT application; etc... In those projects I specify the dependency to the model:

    <dependency>
        <groupId>com.skalio</groupId>
        <artifactId>MyAppInterface</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    
  • When deploying MyAppInterface to Glassfish, I use the following syntax:

asadmin deploy --type osgi --name MyAppInterface /path/to/MyAppInterface-1.0-SNAPSHOT.jar

  • I understand it that this is placing the model on the classpath of Glassfish, similar to a mysql-connector, only OSGi-style.

I let all these projects be built by a central jenkins CI server, which deploys the artifacts to our internal maven repository. We then add the internal repository in pom.xml of each project. As a result, everyone automatically works with the latest stable MyAppInterface, even if they don't have the code checked out in NetBeans / Eclipse.

Let me know if you need more examples.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜