我有一个构建api,ejb和核心java模块的ear
构建pom
。但是当我部署并启动JBoss
时,它会使用耳朵名称部署ejb
JNDI
名称。例如,JNDI
名称为server-component-ear-0.0.1-SNAPSHOT/MyServiceBean/local
这里MyServiceBean是我要从JNDI
视图中查找的ejb。它在ejb模块中。我的最后一个名字是server-component-ear-0.0.1-SNAPSHOT.ear
其中包含
-lib
-META-INF
-server-component-ejb-0.0.1-SNAPSHOT.jar
-server-component-core-0.0.1-SNAPSHOT.jar
听到我的ear
pom
文件
<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>
我用来运行pom
以创建maven build
的服务器组件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>
以下是application.xml
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>
如何让它工作,因为JNDI
名称应该只是MyServiceBean/local
答案 0 :(得分:1)
我不知道我是否完全理解您的问题,但请记住,当部署会话bean时,服务器使用预定义语法将其绑定到JNDI名称。
似乎您正在使用ejb 3.1,如果是这种情况,您可以看到完整的语法描述here(参见第4章,4.4全局JNDI访问。)
JBoss作为符合Java EE的服务器遵循规范所说的,这就是为什么组件以这种方式绑定的原因。 据我所知,您无法更改JNDI绑定名称语法。
答案 1 :(得分:1)
我能解决这个问题。 This link帮助我尝试了。我所做的是将前面的"java:module/"
添加到jndi查找中,以便从bean
开始读取module
。该链接将有助于更清楚地理解它。另请注意,我最后删除了/local
。现在我只查找bean。 IService
interface
由两个不同的beans
使用,现在没有任何问题。
这是我从Java SE client
查找bean的方法。
String jndi = "MyService" // this is a run time parameter. Can be 'MyAnotherService'
IService bean = (IService) initialContext.lookup("java:module/"+jndi+"Bean");
我没有更改bean
课程中的任何注释。因为没有什么能改变jndi的名字。 :(
@Local
public interface IService { // interface}
@Stateless
public class MyServiceBean implements IService { // bean 1}
@Stateless
public class MyAnotherServiceBean implements IService { // bean 2}
现在我不依赖于耳朵或我的ejb jar名称。 感谢加布里埃尔的帮助!!!
答案 2 :(得分:1)
我能够以另一种方式克服这个问题。 我已经配置了maven ear插件来创建无版本模块。
<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>