How To Create A EJB 3.x Project Using Maven in Eclipse - Part 2
How To Create A EJB 3.x Project Using Maven in Eclipse - Part 2
How To Create A EJB 3.x Project Using Maven in Eclipse - Part 2
By Nithya Vasudevan
October 14, 2016
1 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
In Part 1 of this tutorial, we saw how to develop and deploy EJB in JBoss AS using
Maven in Eclipse. In this EJB Maven tutorial we will see how to develop and run
the EJB client (using Maven) to access the ejb.
2 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
This screen prompts for project workspace location. Make sure “Use default Workspace
location” and “Create a simple project (skip archetype selection)” are selected and click Next.
3 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
Now we have to con�gure the project by entering the following details and click Finish.
Enter Group Id: as “com.theopentutorials.ejb3.client“
Enter Artifact Id as “ejbclientmavendemo“
Enter Version: as “1.0-SNAPSHOT“
Packaging: jar
Name: EJB3 Client Maven
4 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
5 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
package com.theopentutorials.ejb3;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
3. Now create another Java class “Client” in the same package and copy the following code.
package com.theopentutorials.ejb3;
import javax.naming.Context;
6 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
import javax.naming.NamingException;
import com.theopentutorials.ejb3.HelloWorld;
} catch (NamingException e) {
e.printStackTrace();
}
return bean;
}
7 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
/*
* The module name is the JAR name of the deployed EJB without the .jar
* suffix.
*/
String moduleName = "ejbmavendemo-1.0-SNAPSHOT";
/*
* AS7 allows each deployment to have an (optional) distinct name. This
* can be an empty string if distinct name is not specified.
*/
String distinctName = "";
return name;
}
8 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
<?xml version="1.0"?>
<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.theopentutorials.ejb3.client</groupId>
<artifactId>ejbclientmavendemo</artifactId>
<version>1.0-SNAPSHOT</version>
<name>EJB3 Client Maven</name>
<packaging>jar</packaging>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
9 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
<version.org.jboss.as.plugins.maven.plugin>7.3.Final</version.org.jboss.as.plugins.maven.plugin>
<version.org.jboss.spec.jboss.javaee.6.0>3.0.0.Final</version.org.jboss.spec.jboss.javaee.6.0>
<dependencyManagement>
<dependencies>
<!-- Define the version of JBoss' Java EE 6 APIs we want to use -->
<!-- JBoss distributes a complete set of Java EE 6 APIs including a
Bill
of Materials (BOM). A BOM specifies the versions of a "stack"
(or a collection)
of artifacts. We use this here so that we always get the
correct versions
of artifacts. Here we use the jboss-javaee-6.0 stack (you can
read this as
the JBoss stack of the Java EE 6 APIs). You can actually use
this stack with
any version of JBoss AS that implements Java EE 6, not just
JBoss AS 7! -->
<dependency>
10 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${version.org.jboss.spec.jboss.javaee.6.0}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>${version.org.jboss.as}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Import the transaction spec API, we use runtime scope because we aren't
using any direct reference to the spec API in our client code -->
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Import the EJB 3.1 API, we use runtime scope because we aren't using
any direct reference to EJB spec API in our client code -->
<dependency>
11 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>runtime</scope>
</dependency>
<!-- We depend on the EJB remote business interfaces of this application -->
<dependency>
<groupId>com.theopentutorials.ejb3</groupId>
<artifactId>ejbmavendemo</artifactId>
<type>ejb-client</type>
<version>${project.version}</version>
</dependency>
<!-- JBoss EJB client API jar. We use runtime scope because the EJB client
API isn't directly used in this example. We just need it in our
runtime classpath -->
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
12 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
<scope>runtime</scope>
</dependency>
<!-- The client needs JBoss remoting to access the server -->
<dependency>
<groupId>org.jboss.remoting3</groupId>
<artifactId>jboss-remoting</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
13 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
<!-- Add the maven exec plugin to allow us to run a java program via
maven -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${version.exec.plugin}</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<workingDirectory>${project.build.directory}/exec-
working-directory</workingDirectory>
<arguments>
<!-- automatically creates the classpath
using all project dependencies,
14 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
<argument>com.theopentutorials.ejb3.Client</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
2. exec-maven-plugin
Since our ejb client is a Java program, to run it we use the exec-maven-plugin
which helps to execute system and Java programs. We need to specify the
executable (i.e. java), classpath, and the java class
(com.theopentutorials.ejb3.Client). The classpath is left empty because the plugin
includes the necessary classpath arguments based on the dependencies provided.
15 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
We depend on the EJB remote business interfaces of this application to run the client. So we
need to specify the ejb client jar dependency. The <type> tag with value “ejb-client” is used to
specify this project’s dependency on the EJB client jar.
<dependency>
<groupId>com.theopentutorials.ejb3</groupId>
<artifactId>ejbmavendemo</artifactId>
<type>ejb-client</type>
<version>${project.version}</version>
</dependency>
16 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
remote.connectionprovider.create.options.org.xnio.Options.SSL_E
NABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_
POLICY_NOANONYMOUS=false
PROJECT STRUCTURE
17 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
18 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
OUTPUT
19 of 20 2017/12/29, 11:19
How to create a EJB 3.x project using Maven in Eclipse – Part 2 – iByte... https://ibytecode.com/blog/how-to-create-a-ejb-3-x-project-using-maven-i...
20 of 20 2017/12/29, 11:19