Build EJB3 with Maven 2
I'm Maven newbie. I'm very happy that I have found a way to compile EJB 3 with Maven. Here is my recipe :) Actually it isn't mine (It is came from the book "POJO's in Action" source code example), but I hope that my post will be useful for somebody. Maven is complex and it is something like new religion ;)
I have JBoss EJB 3 embeddable alpha and want to built my EJBs with Maven 2. What should I do ? The way of adding some third-party jars is a kind of challenge :) Official docs is here. In practice it's looks like this :
set EJB3_LIB=C:\server\jboss-EJB-3.0_Embeddable_ALPHA\libAnd then a lot of almost identical calls for every jar file in EJB3_LIB directory. Full *.cmd file is long and I don't want to list it here.
call mvn install:install-file
-DgeneratePom=true
-Dfile=%EJB3_LIB%\antlr-2.7.5H3.jar
-DgroupId=jboss-ejb3-embeddable_alpha3
-DartifactId=antlr-2.7.5H3
-Dversion=1.0alpha3 -Dpackaging=jar
Resulting POM file is :
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycoolcompany</groupId>
<artifactId>Maven2-EJB3-Compile</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>EJB 3 Compile with Maven 2</name>
<url>http://localhost</url>
<dependencies>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>antlr-2.7.5H3</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>asm-attrs</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>asm</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>cglib-2.1.1</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>commons-collections</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>commons-logging-api</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>concurrent</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>dom4j</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>hibernate3</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>hsqldb</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>javassist</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-aop-jdk50</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-aspect-library-jdk50</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-common-jdbc-wrapper</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-common</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-container</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-dependency</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-ejb3</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-ejb3x</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-j2ee</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-j2se</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-jca</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-local-jdbc</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-microcontainer</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-remoting</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-system</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-transaction</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss-xa-jdbc</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jboss</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jbossmq</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jbosssx</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>jnpserver</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>log4j</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>resolver</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>trove</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>xercesImpl</artifactId>
<version>1.0alpha3</version>
</dependency>
<dependency>
<groupId>jboss-ejb3-embeddable_alpha3</groupId>
<artifactId>xml-apis</artifactId>
<version>1.0alpha3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Don't tell me that maven is easier than Ant... I hope that there is a more elegant
way to build EJBs with Maven.
UPD
Complete example with source code is here : http://code.google.com/p/ostas-blog-src/

8 comments:
I think the problem is you're using EJB, not Maven. Try this:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.0.3</version>
</dependency>
;-)
Hi Matt !
I'll take a look at Spring, I promise :)Spring is not easy-to-learn beat.
I was a fan of spring awhile back. In my opinion Spring has become bloated with loads of things. In my opinion.EJB3 is not bad either; the history of EJB goes long before Spring and while Spring exists because of those "bad" old days; I think EJB has become much more elegant than Spring is today. Spring could have chosen some better options (like Generifying their stuff for one); instead they chose more commercial route.
Regards
Vyas, Anirudh
Yep, things has canged a little. As I promised to Matt, I had a look at Spring and I found it pretty nice. There are some posts about Spring and AOP here at my blog. Like this or this. And now it's pity for me to read posts like this. But it's still really fun ! :)
I could'nt use plugin xml tags, but you can use formatting as a guide.
plugin
groupId org.apache.maven.plugins groupId
artifactId maven-ejb-plugin artifactId
configuration
ejbVersion 3.0 ejbVersion
configuration
plugin
^^ One plugin declaration. thats it, you're done. :)
oo, i posted a comment on this blog awhile back ... wow thats weird.
Do you have or know of an example app that uses maven2+myfaces+spring+jpa?
@Anirudh Vyas
Maven 2 EJB plugin is only little part of the story, indeed. It's related to packaging EJB inside EAR, as far as I see.The EJB plugin allows to package an EJB module.You can take a look at example here. Project name is EnterpriseApp.
Post a Comment