Build EJB3 with jBoss and Maven 2 - better solution
I'm working on project which is not in touch with EJB3, but Maven 2 is is used intensively. I remember my post about building EJB3 with jBoss and Maven 2. In fact that solution works, but I'm not satisfied with it. Since I'm became a little bit stronger in Maven 2 I decided to improve that solution.
So, the task is to build EJB3 entity and EJB3 session bean with Maven 2 and jBoss dependent jars. First, we setting up non another repository where Maven can find jboss jars :
<repositories>
<repository>
<id>jboss-maven2</id>
<url>http://repository.jboss.com/maven2</url>
</repository>
</repositories>
A little bit of magic should be added :)
<parent>
<groupId>jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>2</version>
</parent>
And finally, dependencies. JPA :
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-persistence-api</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
EJB3 :
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-ejb-api</artifactId>
<version>4.2.0.GA</version>
</dependency>
That is all ! Complete pom.xml looks like this :
<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.mycompany.beans</groupId>
<artifactId>SimpleEJB3</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>SimpleEJB3</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>2</version>
</parent>
<repositories>
<repository>
<id>jboss-maven2</id>
<url>http://repository.jboss.com/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-persistence-api</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-ejb-api</artifactId>
<version>4.2.0.GA</version>
</dependency>
</dependencies>
</project>
If there is something wrong with this solution, or maybe you have some improvement, give me a sign.
UPD
Complete example with source code is here : http://code.google.com/p/ostas-blog-src/

6 comments:
Thanks a million, saved me several hours!
Hi Emil !
Well, I've spent several hours trying to do the trick :) I wonder why there were no docs how to do it. But this topic is hot and I see that visitors coming from Google with keywords something like +Maven2 +EJB3.
It's very pleasant for me to have a positive feedback. Thanks for comment. Good luck !
Many thanks. I spent tone of hours looking how to link jboss, ejb with maven.
@Morf3usz
Friendly speaking, I'm too :) Thanks for comment !
My pom.xml is currently as follows :
<?xml version="1.0" encoding="UTF-8"?>
<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.vertomind.idm</groupId>
<artifactId>CleanSystemEJB</artifactId>
<packaging>jar</packaging>
<version>0.0.1-dev</version>
<name>Cleaning the IDM</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>2</version>
</parent>
<repositories>
<repository>
<id>jboss-maven2</id>
<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
</repository>
</repositories>
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>ejb3unit</id>
<name>ejb3unit repository</name>
<url>http://ejb3unit.sourceforge.net/maven2</url>
</repository>
</repositories>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>1.0.1.GA</version>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-ejb-api</artifactId>
<version>4.2.0.GA</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I dunno how to post this better that this ?
ogromnoe spasibo vam za vashi trudi
Post a Comment