0

I have an ear build pom which build api, ejb, and core java module. But when I deploy and start the JBoss, it deploy the ejb JNDI name with the ear name. For example the JNDI name is server-component-ear-0.0.1-SNAPSHOT/MyServiceBean/local

Here the MyServiceBean is my ejb that I want to lookup from JNDI view. and it is inside ejb module. And my final ear name is server-component-ear-0.0.1-SNAPSHOT.ear which contains

-lib
-META-INF
-server-component-ejb-0.0.1-SNAPSHOT.jar
-server-component-core-0.0.1-SNAPSHOT.jar

Hear is my ear pom file

    <parent>
    <groupId>xxx.group.abc</groupId>
    <artifactId>component-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    </parent>
    <name>COMPONENT EAR</name>
    <artifactId>server-component-ear</artifactId>
    <packaging>ear</packaging>
    <dependencies>
      <dependency>
        <groupId>xxx.group.abc</groupId>
        <artifactId>component-ejb</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>ejb</type>
         <exclusions>
            <exclusion>
                <groupId>xxx.group.xyz</groupId>
                <artifactId>some.artifact</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>xxx.group.abc</groupId>
        <artifactId>server-component-core</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>jar</type>
    </dependency>
   </dependencies>
   <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                 <modules>
                     <jarModule>
                        <groupId>xxx.group.abc</groupId>
                        <artifactId>component-core</artifactId>
                        <bundleDir>/</bundleDir>
                        <includeInApplicationXml>true</includeInApplicationXml>
                    </jarModule>
                 </modules>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
        </plugin>
    </plugins>
     <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                  <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-ear-plugin</artifactId>
                                    <versionRange>[2.8,)</versionRange>
                                     <goals>
                                        <goal>generate-application-xml</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
           </plugins>
         </pluginManagement>
    </build>

Server component pom file which I used to run maven build to create the ear.

<name>SERVER COMPONENT</name>

<groupId>xxx.group.abc</groupId>
<artifactId>server-component-parent</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>

<modules>
    <module>api</module>
    <module>ejb</module>
    <module>core</module>
    <module>ear</module>
</modules>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>
    </dependencies>
</dependencyManagement>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Here is the application.xml in ear

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
  <display-name>server-component-ear</display-name>
  <module>
     <java>server-component-core-0.0.1-SNAPSHOT.jar</java>
  </module>
  <module>
     <ejb>server-component-ejb-0.0.1-SNAPSHOT.jar</ejb>
  </module>
</application>

How can I make it to work as the JNDI name should only be MyServiceBean/local

user2771655
  • 1,052
  • 3
  • 20
  • 38

3 Answers3

1

I don't know if I completely understand your question, but take in mind that when a session bean is deployed the server binds it to a JNDI name using a predefined syntax.

It seems to be that you are using ejb 3.1, if it is the case you can see a complete syntax description here (see Chapter 4, 4.4 Global JNDI Access.)

JBoss as a Java EE compliant server follows what the specification says, this is the reason why your components are binding in such way. According to my knowledge, you are not able to change the JNDI binding name syntax.

Gabriel Aramburu
  • 2,951
  • 2
  • 16
  • 20
  • thanks for the reply, I understood how its calling in ear environment. My issue was yesterday I converted my project from jar to ear. when I use jar I was able to lookup the bean by its name. like " MyServiceBean/local " But with the ear I can't do it anymore. Thats my issue. I did not mentioned the '@name' and '@mappedName' annotations in my bean and interface. So if I defined those I should be able to define my own JNDI name, am I? – user2771655 Mar 08 '14 at 00:25
  • I tried many ways. Can you guide me how to define my own JNDI name to lookup? I can not use the ejb jar name to lookup jndi. I use annotations and do not have ejb-jar.xml either. what is the solution for me? – user2771655 Mar 08 '14 at 16:51
  • I think it is not possible, if you now have an ear I think the best option it's to change the jndi name including the ear-name as part of it. May be [this](https://community.jboss.org/message/647139#647139) link can help you – Gabriel Aramburu Mar 08 '14 at 22:25
  • This is very bad. Isn't it? when ever we change the ear version then we need to change the java file to lookup the bean. Is this the way the whole world work? – user2771655 Mar 09 '14 at 02:08
1

I was able to fix this. This link helped me to try. What I did was add the "java:module/" in front to the jndi lookup so that it reads the bean from module onwards. That link will help to understand it more clearly. Also note that I removed the /local at the end. Now I just lookup the bean only. IService interface is use by two different beans without any problem now.

This is how I lookup the bean from Java SE client.

String   jndi = "MyService" // this is a run time parameter. Can be 'MyAnotherService' 
IService bean = (IService) initialContext.lookup("java:module/"+jndi+"Bean");

And I did not change any annotation in the bean class. Because nothing worked for me to change the jndi name. :(

 @Local
 public interface IService { // interface}


 @Stateless
 public class MyServiceBean implements IService { // bean 1}


 @Stateless
 public class MyAnotherServiceBean implements IService { // bean 2}

Now I am not depend on the ear or my ejb jar name. Thanks Gabriel for help!!!

user2771655
  • 1,052
  • 3
  • 20
  • 38
  • see also http://stackoverflow.com/a/26033585/160799 for an example that includes filtering only for modules (optimization?) – Gregor Nov 29 '16 at 10:48
1

I was able to overcome this issue the other way. I have configured maven ear plugin to create version-less modules.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <version>5</version>
        <defaultLibBundleDir>/lib</defaultLibBundleDir>
        <generateApplicationXml>true</generateApplicationXml>
        <finalName>appName-ear</finalName>
        <modules>
            <ejbModule>
                <groupId>com.abc</groupId>
                <artifactId>appName-ejb</artifactId>
                <bundleFileName>appName-ejb</bundleFileName>
            </ejbModule>
            <webModule>
                <groupId>com.abc</groupId>
                <artifactId>appName-web</artifactId>
                <bundleFileName>appName-web</bundleFileName>
            </webModule>
        </modules>
    </configuration>
</plugin>
kqr
  • 406
  • 8
  • 12
  • wow totally overlooked that and forgot about the Maven ear config, exactly what I needed, thanks a log @kqr ! – Gregor Nov 30 '16 at 16:04