I have EJBs in EJB 3.1 which I am trying to deploy in JBoss EAP 6, but when I start the server. It appends version no in JNDI names as shown below.
18:27:57,068 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-6) JNDI bindings for session bean named TestService in deployment unit subdeployment "TestGroup-war-3_0_0-SNAPSHOT.war" of deployment "TestGroup-ear-3_0_0-SNAPSHOT.ear" are as follows:
java:global/TestGroup-ear-3_0_0-SNAPSHOT/TestGroup-war-3_0_0-SNAPSHOT/TestService!org.pkg.ejb.local.CRMDataServiceLocal
java:app/TestGroup-war-3_0_0-SNAPSHOT/TestService!org.pkg.ejb.local.CRMDataServiceLocal
java:module/TestService!org.pkg.ejb.local.CRMDataServiceLocal
java:global/TestGroup-ear-3_0_0-SNAPSHOT/TestGroup-war-3_0_0-SNAPSHOT/TestService
java:app/TestGroup-war-3_0_0-SNAPSHOT/TestService
java:module/TestService
How do I remove version number "-3_0_0-SNAPSHOT" from my JNDI names ? I have ejb-jar.xml which is placed in ejb jar file when I deploy the ear.
According to the EJB JNDI Naming Reference, the JNDI lookup name for a session bean has the following syntax:
ejb:<appName>/<moduleName>/<distinctName>/<beanName>!<viewClassName>?stateful
Therefore, what you want can be achieved in two ways:
In order to remove the version from your WAR you could just do the following in your WAR's POM:
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
Regarding your EAR, in order to remove the version from it, you could place the following in your EAR's POM:
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
(...)
<finalName>${project.artifactId}</finalName>
(...)
</configuration>
</plugin>
</plugins>
</build>
With the configuration above, you'd have something like:
.../TestGroup-ear/TestGroup-war/...
Create an ejb-jar.xml, with the content below, and place it under your WAR's src/main/webapp/WEB-INF folder:
<ejb-jar xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd"
version="3.2">
<module-name>someModuleName</module-name>
</ejb-jar>
Afterwards, place an application.xml file, under your EAR's src/main/resources/META-INF folder, with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd"
version="7">
<application-name>someApplicationName</application-name>
</<module>
<web>
<web-uri>TestGroup-war-${project.version}.war</web-uri>
<context-root>testGroup</context-root>
</web>
</module>
</application>
Then, on your JNDI, you'll have something like:
java:global/someApplicationName/someModuleName/TestService!org.pkg.ejb.local.CRMDataServiceLocal
java:app/someModuleName/TestService!org.pkg.ejb.local.CRMDataServiceLocal
java:module/TestService!org.pkg.ejb.local.CRMDataServiceLocal
java:global/someApplicationName/someModuleName/TestService
java:app/someModuleName/TestService
java:module/TestService
As of version 2.5, the Maven EAR plugin has the option no-version
that can be set to the property fileNameMapping
, in order to omit the version from your artifact:
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
(...)
<fileNameMapping>no-version</fileNameMapping>
(...)
</configuration>
</plugin>
The answers above did not work for me. In my case I upgraded the maven-ear-plugin to version 2.10, and provided the 'fileNameMapping' property as 'no-version':
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<!-- Tell Maven we are using Java EE 7 -->
<version>7</version>
<fileNameMapping>no-version</fileNameMapping>
<generateApplicationXml>true</generateApplicationXml>
<defaultLibBundleDir>/lib</defaultLibBundleDir>
<modules>
<ejbModule>
<groupId>${project.groupId}</groupId>
<artifactId>dpc-ejb</artifactId>
<bundleDir>/</bundleDir>
</ejbModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>dpc-war</artifactId>
<bundleDir>/</bundleDir>
<contextRoot>dpc</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With