Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of version number in JNDI names, Jboss EAP 6, EJB 3.1

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.

like image 685
Jigar Naik Avatar asked Mar 23 '16 10:03

Jigar Naik


2 Answers

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:

  1. Modify the name of your deliverable files (WAR and EAR)

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/...
  1. Make use of ejb-jar.xml and application.xml files

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

UPDATE

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>
like image 119
António Ribeiro Avatar answered Sep 21 '22 18:09

António Ribeiro


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>
like image 39
Meindert Avatar answered Sep 24 '22 18:09

Meindert