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
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!!!