客户端上的 JNDI 查找 JMS 资源失败

JNDI lookup on client fails for JMS resource

试图使 JMS 教程中的一个简单程序正常工作时,我快要失去理智了。本教程的源代码是 here(忽略 samples 文件夹),但它的组织不正确(MDB 项目的依赖项必须包含在 SE 项目和其他小部分中)。如您所见,该程序由一个 EJB 模块组成,该模块包含要部署在应用程序服务器上的 MDB(我使用的是 Glassfish 5)和两个 Java SE 客户端,它们都有一个 main 方法。

ConnectionFactoryTopic 创建和配置 JMS 资源后,MDB 模块部署完美(如果资源的 JNDI 名称与 MDB 上指定的名称不同或根本不存在,部署失败)。但是,当我尝试使用相同的 JNDI 名称启动这两个客户端中的任何一个时,会发生以下异常:

Aug 30, 2019 7:33:01 AM com.sun.enterprise.connectors.ActiveRAFactory createActiveResourceAdapter
SEVERE: RAR6001 : Class Not found : com.sun.messaging.jms.ra.ResourceAdapter
Aug 30, 2019 7:33:01 AM com.sun.enterprise.connectors.ActiveRAFactory createActiveResourceAdapter
SEVERE:
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Error in creating active RAR
        at com.sun.enterprise.connectors.ActiveRAFactory.createActiveResourceAdapter(ActiveRAFactory.java:87)
        at com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl.createActiveResourceAdapter(ResourceAdapterAdminServiceImpl.java:188)
        at com.sun.enterprise.connectors.ConnectorRuntime.createActiveResourceAdapter(ConnectorRuntime.java:403)
        at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance(ConnectorObjectFactory.java:83)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
        at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:503)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:463)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:414)
        at javax.naming.InitialContext.lookup(InitialContext.java:417)
        at store.OrderProducer.main(OrderProducer.java:21)
        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:498)
        at org.codehaus.mojo.exec.ExecJavaMojo.run(ExecJavaMojo.java:297)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.sun.messaging.jms.ra.ResourceAdapter
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at com.sun.enterprise.connectors.ActiveRAFactory.createActiveResourceAdapter(ActiveRAFactory.java:79)
        ... 15 more

[WARNING]
java.lang.reflect.InvocationTargetException
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: javax.naming.NamingException: Lookup failed for 'jms/javaee7/ConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:467)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:414)
    at javax.naming.InitialContext.lookup (InitialContext.java:417)
    at store.OrderProducer.main (OrderProducer.java:21)
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: javax.naming.NamingException: Failed to look up ConnectorDescriptor from JNDI
    at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance (ConnectorObjectFactory.java:90)
    at javax.naming.spi.NamingManager.getObjectInstance (NamingManager.java:321)
    at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance (SerialContext.java:503)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:463)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:414)
    at javax.naming.InitialContext.lookup (InitialContext.java:417)
    at store.OrderProducer.main (OrderProducer.java:21)
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Error in creating active RAR
    at com.sun.enterprise.connectors.ActiveRAFactory.createActiveResourceAdapter (ActiveRAFactory.java:87)
    at com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl.createActiveResourceAdapter (ResourceAdapterAdminServiceImpl.java:188)
    at com.sun.enterprise.connectors.ConnectorRuntime.createActiveResourceAdapter (ConnectorRuntime.java:403)
    at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance (ConnectorObjectFactory.java:83)
    at javax.naming.spi.NamingManager.getObjectInstance (NamingManager.java:321)
    at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance (SerialContext.java:503)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:463)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:414)
    at javax.naming.InitialContext.lookup (InitialContext.java:417)
    at store.OrderProducer.main (OrderProducer.java:21)
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.sun.messaging.jms.ra.ResourceAdapter
    at java.net.URLClassLoader.findClass (URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:357)
    at com.sun.enterprise.connectors.ActiveRAFactory.createActiveResourceAdapter (ActiveRAFactory.java:79)
    at com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl.createActiveResourceAdapter (ResourceAdapterAdminServiceImpl.java:188)
    at com.sun.enterprise.connectors.ConnectorRuntime.createActiveResourceAdapter (ConnectorRuntime.java:403)
    at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance (ConnectorObjectFactory.java:83)
    at javax.naming.spi.NamingManager.getObjectInstance (NamingManager.java:321)
    at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance (SerialContext.java:503)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:463)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:414)
    at javax.naming.InitialContext.lookup (InitialContext.java:417)
    at store.OrderProducer.main (OrderProducer.java:21)
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.173 s
[INFO] Finished at: 2019-08-30T07:33:02+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project store-se: An exception occured while executing the Java class. null: InvocationTargetException: Lookup failed for 'jms/javaee7/ConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}: Failed to look up ConnectorDescriptor from JNDI: Error in creating active RAR: com.sun.messaging.jms.ra.ResourceAdapter -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project store-se: An exception occured while executing the Java class. null
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    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:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null
    at org.codehaus.mojo.exec.ExecJavaMojo.execute (ExecJavaMojo.java:352)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    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:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.reflect.InvocationTargetException
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: javax.naming.NamingException: Lookup failed for 'jms/javaee7/ConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:467)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:414)
    at javax.naming.InitialContext.lookup (InitialContext.java:417)
    at store.OrderProducer.main (OrderProducer.java:21)
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: javax.naming.NamingException: Failed to look up ConnectorDescriptor from JNDI
    at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance (ConnectorObjectFactory.java:90)
    at javax.naming.spi.NamingManager.getObjectInstance (NamingManager.java:321)
    at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance (SerialContext.java:503)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:463)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:414)
    at javax.naming.InitialContext.lookup (InitialContext.java:417)
    at store.OrderProducer.main (OrderProducer.java:21)
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Error in creating active RAR
    at com.sun.enterprise.connectors.ActiveRAFactory.createActiveResourceAdapter (ActiveRAFactory.java:87)
    at com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl.createActiveResourceAdapter (ResourceAdapterAdminServiceImpl.java:188)
    at com.sun.enterprise.connectors.ConnectorRuntime.createActiveResourceAdapter (ConnectorRuntime.java:403)
    at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance (ConnectorObjectFactory.java:83)
    at javax.naming.spi.NamingManager.getObjectInstance (NamingManager.java:321)
    at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance (SerialContext.java:503)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:463)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:414)
    at javax.naming.InitialContext.lookup (InitialContext.java:417)
    at store.OrderProducer.main (OrderProducer.java:21)
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.sun.messaging.jms.ra.ResourceAdapter
    at java.net.URLClassLoader.findClass (URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:357)
    at com.sun.enterprise.connectors.ActiveRAFactory.createActiveResourceAdapter (ActiveRAFactory.java:79)
    at com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl.createActiveResourceAdapter (ResourceAdapterAdminServiceImpl.java:188)
    at com.sun.enterprise.connectors.ConnectorRuntime.createActiveResourceAdapter (ConnectorRuntime.java:403)
    at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance (ConnectorObjectFactory.java:83)
    at javax.naming.spi.NamingManager.getObjectInstance (NamingManager.java:321)
    at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance (SerialContext.java:503)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:463)
    at com.sun.enterprise.naming.impl.SerialContext.lookup (SerialContext.java:414)
    at javax.naming.InitialContext.lookup (InitialContext.java:417)
    at store.OrderProducer.main (OrderProducer.java:21)
    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:498)
    at org.codehaus.mojo.exec.ExecJavaMojo.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)

除GlassFish 5 外,我尝试同时使用最新版本的Payara 服务器和GlassFish 4,但问题仍然存在。请注意,我在客户端 SE 项目中包含 Java EE 7 API 依赖项和 gf-client 5.1.0 依赖项,以及 MDB 项目的依赖项。正如堆栈似乎暗示的那样,ResourceAdapter class 丢失了,这很奇怪,因为我在项目中包含了 gf-client 依赖项。

这是 MDB 消费者的代码,部署得很好(不确定它是否有效,因为我无法在 SE 客户端启动生产者):

@MessageDriven(mappedName = "jms/javaee7/Topic", activationConfig = {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "orderAmount > 1000")
})
public class ExpensiveOrderMDB implements MessageListener {

    @Override
    public void onMessage(Message message) {
        try {
            OrderDTO order = message.getBody(OrderDTO.class);
            System.out.println(String
                .format("Expensive order received: %s", order));
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }

}

下面是 SE 生产者和消费者的代码:

public class OrderProducer {

    private static final Float TOTAL_AMOUNT = 2500f;

    public static void main(String[] args) throws NamingException {
        Float totalAmount = OrderProducer.TOTAL_AMOUNT;
        OrderDTO order = 
                new OrderDTO(1234l, new Date(), "Betty Moreau", totalAmount);
        Context jndiContext = new InitialContext();
        ConnectionFactory connectionFactory = (ConnectionFactory)
                jndiContext.lookup("jms/javaee7/ConnectionFactory");
        Destination topic = (Destination) 
                jndiContext.lookup("jms/javaee7/Topic");
        try (JMSContext jmsContext = connectionFactory.createContext()) {
            jmsContext.createProducer()
                    .setProperty("orderAmount", totalAmount)
                    .send(topic, order);
            System.out.println(String.format("Sent order: %s", order));
        }
    }

}
public class OrderConsumer {

    public static void main(String[] args) throws NamingException {
        Context jndiContext = new InitialContext();
        ConnectionFactory connectionFactory = (ConnectionFactory)
                jndiContext.lookup("jms/javaee7/ConnectionFactory");
        Destination topic = (Destination)
                jndiContext.lookup("jms/javaee7/Topic");
        try (JMSContext jmsContext = connectionFactory.createContext()) {
            while (true) {
                OrderDTO order = jmsContext.createConsumer(topic)
                        .receiveBody(OrderDTO.class);
                System.out.println(String.format("Received order: %s", order));
            }
        }
    }

}

我确信这个问题很愚蠢而且很容易解决,但我无法解决这个问题。任何帮助将不胜感激。

我已经能够通过在客户端项目中添加 imqjmsra 依赖项并将 Java EE API 依赖项版本从 7.0 升级到 8.0 来解决问题。 编辑:意识到我可以删除 Java EE API 依赖关系,因为我实际上并没有在项目中使用它。有点奇怪,因为如果不从 7.0 升级到 8.0 会导致错误。