quality@glassfish.java.net

Re: EJB development with Maven, making it easier and more fool proof.

From: Richard Kolb <rjdkolb_at_gmail.com>
Date: Tue, 16 Mar 2010 10:34:32 +0200

Hi Wouter

On 16 March 2010 10:23, Wouter van Reeven <wouter_at_van.reeven.nl> wrote:

>
> Hmmm I'm having trouble downloading jars for java mail, jmx, jmxtools
> and jmxri. The versions that are referred to no longer exist. When I
> exclude the dependencies building the jar goes ok.
>

hmmm...
I am using
                <dependency>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                        <version>1.2.15</version>
                </dependency>



>
> It looks like Maven doesn't include the log4j.jar file which may very
> well be resolved by adding the maven-assembly plugin as you suggest. I
> haven't tried that yet.
>
> It looks like the maven-ejb-plugin doesn't include any jars that are
> needed at runtime and that's probably why you get the CNFE at deploy
> time. I *guess* the maven-ejb-plugin isn't prepared yet for Java EE6 and
> it assumes that all necessary external jars are in an EAR file. But
> that's just a guess.
>
> So, the issue that was fixed by Homer is just a side effect that arose
> by coincidence :-)
>

Yes, but it is more than that. It effects JavaEE 5 as well.
It is indeed a side effect on how Maven packages EJB's by default.


The normal EJB packaging does not include the JAR's
But if you add the following to the pom.xml

            <plugin>
               <artifactId>maven-assembly-plugin</artifactId>
               <configuration>
                   <descriptorRefs>
                       <descriptorRef>jar-with-dependencies</descriptorRef>
                   </descriptorRefs>
               </configuration>
               <executions>
                   <execution>
                       <id>make-assembly</id>
                       <phase>package</phase>
                       <goals>
                           <goal>single</goal>
                       </goals>
                   </execution>
               </executions>
           </plugin>

you will get two JAR's in your target directory.

1) yourapp-0.0.2-SNAPSHOT.jar (with no libs, which is the default EJB
packaging)
2) yourapp-0.0.2-SNAPSHOT-jar-with-dependencies.jar (with all the libs, does
not cause GF issue)


regards
Richard.