使用 JNDI ClassNotFoundException javax.ejb.EJBException 的 WildFly 10 远程 EJB 调用
WildFly 10 Remote EJB invocation using JNDI ClassNotFoundException javax.ejb.EJBException
我安装了 Java 8 & WildFly (JBoss) 10.0。我已经在 "remote" 服务器上部署了带有远程 EJB 的 emsa.jar
文件。
我正在尝试使用 JNDI 从单独的客户端应用程序中调用 EJB 中的方法,方法是 运行 客户端的主要方法作为 Eclipse 中的 Java 应用程序,但我得到以下信息错误:
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@61f8bee4, receiver=Remoting connection EJB receiver [connection=Remoting connection <545ebbdd>,channel=jboss.ejb,nodename=skb]} on channel Channel ID d234d46a (outbound) of Remoting connection 395b72b3 to localhost/127.0.0.1:8080
Exception in thread "naming-client-message-receiver-1-thread-1" java.lang.NoClassDefFoundError: javax/ejb/EJBException
at org.jboss.ejb.client.SerializedEJBInvocationHandler.readResolve(SerializedEJBInvocationHandler.java:110)
at org.jboss.ejb.client.SerializedEJBInvocationHandler.readResolve(SerializedEJBInvocationHandler.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.marshalling.reflect.SerializableClass.callReadResolve(SerializableClass.java:417)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1299)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:213)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNestedObject(RiverUnmarshaller.java:169)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1254)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:213)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:45)
at org.jboss.naming.remote.protocol.v1.Protocol.read(Protocol.java:156)
at org.jboss.naming.remote.protocol.v1.Protocol.read(Protocol.java:149)
at org.jboss.naming.remote.protocol.v1.BaseProtocolCommand.readResult(BaseProtocolCommand.java:59)
at org.jboss.naming.remote.protocol.v1.Protocol.handleClientMessage(Protocol.java:149)
at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver.run(RemoteNamingStoreV1.java:232)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: javax.ejb.EJBException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 more
javax.naming.NamingException: Unable to invoke lookup, status=WAITING
at org.jboss.naming.remote.protocol.v1.Protocol.execute(Protocol.java:98)
at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:95)
at org.jboss.naming.remote.client.HaRemoteNamingStore.operation(HaRemoteNamingStore.java:276)
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:132)
at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)
at org.jboss.naming.remote.client.RemoteContext.lookupInternal(RemoteContext.java:104)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:93)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:146)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.kelly_ann.employeemgmt.Main.main(Main.java:38)
客户端class中的代码是:
package com.k_a.employeemgmt;
import java.util.List;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.k_a.employeemgmt.EmployeeMgmtService;
import com.k_a.employeemgmt.domain.Employee;
public class Main {
// this remotely invokes the server's EmployeeMgmtService.getAllEmployees() method.
public static void main(String[] args) {
try {
Properties jndiProperties = new Properties();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProperties.put("jboss.naming.client.ejb.context", true);
System.out.println("MYTESTjndiProperties: " + jndiProperties); // gets here
Context jndi = new InitialContext(jndiProperties);
System.out.println("MYTESTjndi: " + jndi); // gets here
EmployeeMgmtService service = (EmployeeMgmtService)jndi.lookup("emsa/EmployeeMgmtImpl!com.k_a.employeemgmt.EmployeeMgmtService");
System.out.println("MYTESTservice: " + service); // doesn't get to here
List<Employee> employees = service.getAllEmployees();
for(Employee employee : employees) {
System.out.println(employee);
}
}
我的客户端应用程序的 Gradle 构建文件 (build.gradle
) 具有以下依赖项:
apply plugin: 'java'
defaultTasks 'clean', 'compileJava', 'test', 'jar'
jar {
archiveName = "emtc.jar"
}
test.useJUnit()
repositories {
mavenCentral()
}
dependencies {
compile 'jboss:jboss-client:4.0.2'
compile 'org.jboss:jboss-remote-naming:2.0.4.Final'
compile 'org.jboss.xnio:xnio-nio:3.3.6.Final'
testCompile 'junit:junit:4.12'
}
我在最后一天尝试遵循 WildFly/JBoss 文档 here,但没有成功。
有什么想法吗?
我已经写了一篇关于在 Maven 中为 Wildfly 9.0 做的方法的小文章 tutorial。2.Final。所以我只是尝试将其翻译成 Gradle 方式(抱歉,我没有使用 Gradle 的经验)并且我已经调整依赖项以符合 Wildfly 10.0.0.Final 尊重您的需要,以便如果有任何错误的版本组合,您将不会得到 NoClassDefException :
dependencies {
org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:1.0.0.Final
org.jboss:jboss-remote-naming:2.0.4.Final
org.jboss:jboss-ejb-client:2.1.4.Final
org.jboss.xnio:xnio-nio:3.3.4.Final
org.jboss.marshalling:jboss-marshalling-river:1.4.10.Final
org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Final
}
或者直接使用:
dependencies {
org.wildfly:wildfly-client-all:10.0.0.Final
}
但在第二种情况下,您将拥有 JMS 的其他传递依赖项...
顺便说一下,在 Maven 方式中,我经常使用 BOM 依赖,它会自动暗示依赖的 "right" 版本,但我不知道 [=29 中是否有类似的东西=].如果可能,您可以使用此 BOM:
org.wildfly:wildfly-ejb-client-bom:10.0.0.Final
然后你可以省略我上面提到的依赖项的版本。
请告诉我您的反馈。
最终解:
问题是我的 Gradle build.gradle 文件 我也需要应用 'application'
插件 here and call the 'run'
task. Once that was done it worked like a charm! Ended up using the maven repository BOM (from here) 在 Gradle 构建文件中列出,因为那是确保适当的依赖管理的最佳方式。感谢您的帮助!非常感激。 :-)
build.gradle
文件中的最终代码如下:
apply plugin: 'java'
apply plugin: 'application'
defaultTasks 'clean', 'compileJava', 'test', 'jar', 'run'
mainClassName = 'com.k_a.employeemgmt.Main'
jar {
archiveName = "emtc.jar"
}
test.useJUnit()
repositories {
mavenCentral()
}
dependencies {
compile 'org.wildfly:wildfly-ejb-client-bom:10.0.0.Final'
testCompile 'junit:junit:4.12'
}
我安装了 Java 8 & WildFly (JBoss) 10.0。我已经在 "remote" 服务器上部署了带有远程 EJB 的 emsa.jar
文件。
我正在尝试使用 JNDI 从单独的客户端应用程序中调用 EJB 中的方法,方法是 运行 客户端的主要方法作为 Eclipse 中的 Java 应用程序,但我得到以下信息错误:
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@61f8bee4, receiver=Remoting connection EJB receiver [connection=Remoting connection <545ebbdd>,channel=jboss.ejb,nodename=skb]} on channel Channel ID d234d46a (outbound) of Remoting connection 395b72b3 to localhost/127.0.0.1:8080
Exception in thread "naming-client-message-receiver-1-thread-1" java.lang.NoClassDefFoundError: javax/ejb/EJBException
at org.jboss.ejb.client.SerializedEJBInvocationHandler.readResolve(SerializedEJBInvocationHandler.java:110)
at org.jboss.ejb.client.SerializedEJBInvocationHandler.readResolve(SerializedEJBInvocationHandler.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.marshalling.reflect.SerializableClass.callReadResolve(SerializableClass.java:417)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1299)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:213)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNestedObject(RiverUnmarshaller.java:169)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1254)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:213)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:45)
at org.jboss.naming.remote.protocol.v1.Protocol.read(Protocol.java:156)
at org.jboss.naming.remote.protocol.v1.Protocol.read(Protocol.java:149)
at org.jboss.naming.remote.protocol.v1.BaseProtocolCommand.readResult(BaseProtocolCommand.java:59)
at org.jboss.naming.remote.protocol.v1.Protocol.handleClientMessage(Protocol.java:149)
at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver.run(RemoteNamingStoreV1.java:232)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: javax.ejb.EJBException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 more
javax.naming.NamingException: Unable to invoke lookup, status=WAITING
at org.jboss.naming.remote.protocol.v1.Protocol.execute(Protocol.java:98)
at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:95)
at org.jboss.naming.remote.client.HaRemoteNamingStore.operation(HaRemoteNamingStore.java:276)
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:132)
at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)
at org.jboss.naming.remote.client.RemoteContext.lookupInternal(RemoteContext.java:104)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:93)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:146)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.kelly_ann.employeemgmt.Main.main(Main.java:38)
客户端class中的代码是:
package com.k_a.employeemgmt;
import java.util.List;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.k_a.employeemgmt.EmployeeMgmtService;
import com.k_a.employeemgmt.domain.Employee;
public class Main {
// this remotely invokes the server's EmployeeMgmtService.getAllEmployees() method.
public static void main(String[] args) {
try {
Properties jndiProperties = new Properties();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProperties.put("jboss.naming.client.ejb.context", true);
System.out.println("MYTESTjndiProperties: " + jndiProperties); // gets here
Context jndi = new InitialContext(jndiProperties);
System.out.println("MYTESTjndi: " + jndi); // gets here
EmployeeMgmtService service = (EmployeeMgmtService)jndi.lookup("emsa/EmployeeMgmtImpl!com.k_a.employeemgmt.EmployeeMgmtService");
System.out.println("MYTESTservice: " + service); // doesn't get to here
List<Employee> employees = service.getAllEmployees();
for(Employee employee : employees) {
System.out.println(employee);
}
}
我的客户端应用程序的 Gradle 构建文件 (build.gradle
) 具有以下依赖项:
apply plugin: 'java'
defaultTasks 'clean', 'compileJava', 'test', 'jar'
jar {
archiveName = "emtc.jar"
}
test.useJUnit()
repositories {
mavenCentral()
}
dependencies {
compile 'jboss:jboss-client:4.0.2'
compile 'org.jboss:jboss-remote-naming:2.0.4.Final'
compile 'org.jboss.xnio:xnio-nio:3.3.6.Final'
testCompile 'junit:junit:4.12'
}
我在最后一天尝试遵循 WildFly/JBoss 文档 here,但没有成功。
有什么想法吗?
我已经写了一篇关于在 Maven 中为 Wildfly 9.0 做的方法的小文章 tutorial。2.Final。所以我只是尝试将其翻译成 Gradle 方式(抱歉,我没有使用 Gradle 的经验)并且我已经调整依赖项以符合 Wildfly 10.0.0.Final 尊重您的需要,以便如果有任何错误的版本组合,您将不会得到 NoClassDefException :
dependencies {
org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:1.0.0.Final
org.jboss:jboss-remote-naming:2.0.4.Final
org.jboss:jboss-ejb-client:2.1.4.Final
org.jboss.xnio:xnio-nio:3.3.4.Final
org.jboss.marshalling:jboss-marshalling-river:1.4.10.Final
org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Final
}
或者直接使用:
dependencies {
org.wildfly:wildfly-client-all:10.0.0.Final
}
但在第二种情况下,您将拥有 JMS 的其他传递依赖项...
顺便说一下,在 Maven 方式中,我经常使用 BOM 依赖,它会自动暗示依赖的 "right" 版本,但我不知道 [=29 中是否有类似的东西=].如果可能,您可以使用此 BOM:
org.wildfly:wildfly-ejb-client-bom:10.0.0.Final
然后你可以省略我上面提到的依赖项的版本。
请告诉我您的反馈。
最终解:
问题是我的 Gradle build.gradle 文件 我也需要应用 'application'
插件 here and call the 'run'
task. Once that was done it worked like a charm! Ended up using the maven repository BOM (from here) 在 Gradle 构建文件中列出,因为那是确保适当的依赖管理的最佳方式。感谢您的帮助!非常感激。 :-)
build.gradle
文件中的最终代码如下:
apply plugin: 'java'
apply plugin: 'application'
defaultTasks 'clean', 'compileJava', 'test', 'jar', 'run'
mainClassName = 'com.k_a.employeemgmt.Main'
jar {
archiveName = "emtc.jar"
}
test.useJUnit()
repositories {
mavenCentral()
}
dependencies {
compile 'org.wildfly:wildfly-ejb-client-bom:10.0.0.Final'
testCompile 'junit:junit:4.12'
}