Here, we will discuss how to create a Maven Enterprise JavaBeans (EJB) project using the ejb-javaee6
archetype developed by Codehaus, which is a collaborative environment for building open source projects:
$ mvn archetype:generate -B -DgroupId=com.packt.samples -DartifactId=my-ejbapp -Dpackage=com.packt.samples.ejbapp -Dversion=1.0.0 -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=ejb-javaee6 -DarchetypeVersion=1.5
The previous command produces the following skeleton project. You can create your EJB classes inside src/main/java/com/packt/samples/ejbapp/
:
my-ejbapp |-pom.xml |-src/main/java/com/packt/samples/ejbapp/ |-src/main/resources/META-INF/MANIFEST.MF
If you look at the following pom.xml
file inside my-ejbapp
, you will notice that maven-ejb-plugin
is used internally to produce the EJB artifact:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
Even though we highlighted ejb-javaee6
, it is not the best out there for generating a Maven EJB project. The template produced by the ejb-javaee6
archetype is very basic. Oracle WebLogic has developed a better EJB archetype, basic-webapp-ejb
.The following example shows how to use the basic-webapp-ejb
archetype:
$ mvn archetype:generate -B -DarchetypeGroupId=com.oracle.weblogic.archetype -DarchetypeArtifactId=basic-webapp-ejb -DarchetypeVersion=12.1.3-0-0 -DgroupId=com.packt.samples -DartifactId=my-ejbapp -Dpackage=com.packt.samples.ejbapp -Dversion=1.0.0
Prior to executing the previous command, there is more homework to be done. The basic-webapp-ejb
archetype is not available in any public Maven repositories. First, you need to download the WebLogic distribution from http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/wls_12c_netbeans_install/wls_12c_netbeans_install.html and then install it locally by performing the instructions in the README.txt
file. Once the installation is completed, the basic-webapp-ejb archetype and weblogic-maven-plugin
can be installed into the local Maven repository, as follows:
wls12130/wlserver/server/lib
and execute the following command. This will build the plugin JAR file using the WebLogic JarBuilder tool.$ java -jar wljarbuilder.jar -profile weblogic-maven-plugin
weblogic-maven-plugin.jar
file. Now we need to extract it to get the pom.xml
file. From wls12130/wlserver/server/lib
, execute the following command:$ jar xvf weblogic-maven-plugin.jar
pom.xml
file to wls12130/wlserver/server/lib
. From wls12130/wlserver/server/lib
, execute the following command:$ cp META-INF/maven/com.oracle.weblogic/weblogic-maven-plugin/pom.xml .
weblogic-maven-plugin.jar
into the local
Maven repository. From wls12130/wlserver/server/lib
, execute the following command:$ mvn install:install-file -Dfile=weblogic-maven-plugin.jar -DpomFile=pom.xml
basic-webapp-ejb
archetype. To do this, go to wls12130/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.1.3
and execute the following two commands. Note that oracle_common
is a hidden directory. If you are using a different version of WebLogic instead of 12.1.3, use the number associated with your version:$ mvn install:install-file -DpomFile=oracle-maven-sync-12.1.3.pom -Dfile=oracle-maven-sync-12.1.3.jar $ mvn com.oracle.maven:oracle-maven-sync:push -Doracle-maven-sync.oracleHome=/Users/prabath/Downloads/wls12130 -Doracle-maven-sync.testingOnly=false
Once we are done with these steps, you can execute the following command to generate the EJB template project using the WebLogic basic-webapp-ejb
archetype. Make sure that you have the right version for archetypeVersion
. This should match the archetype version that comes with your WebLogic distribution:
$ mvn archetype:generate -B -DarchetypeGroupId=com.oracle.weblogic.archetype -DarchetypeArtifactId=basic-webapp-ejb -DarchetypeVersion=12.1.3-0-0 -DgroupId=com.packt.samples -DartifactId=my-ejbapp -Dpackage=com.packt.samples.ejbapp -Dversion=1.0.0
This command produces the following skeleton project:
my-ejbapp |-pom.xml |-src/main/java/com/packt/samples/ejbapp |-entity/Account.java |-service/AccountBean.java |-service/AccountManager.java |-service/AccountManagerImpl.java |-interceptor/LogInterceptor.java |-interceptor/OnDeposit.java |-src/main/resources/META-INF/persistence.xml |-src/main/scripts |-src/main/webapp/WEB-INF/web.xml |-src/main/webapp/WEB-INF/beans.xml |-src/main/webapp/css/bootstrap.css |-src/main/webapp/index.xhtml |-src/main/webapp/template.xhtml
To package the EJB archive, execute the following command from the my-ejbapp
directory. This will produce basicWebappEjb.war
inside the target
directory. Now you can deploy this WAR file into your Java EE application server, which supports EJB:
$ mvn package
18.118.20.231