URL 方案名称 "http-remoting" 发生在 运行 应用程序 jar 时

Invalid URL scheme name "http-remoting" occurring when running application jar

我正在使用 JBoss JMS 快速启动项目 (HelloWorld-JMS) 之一,它使用 JMS 写入消息队列。该队列已在 JBoss XML 配置文件中定义。当我们从 IDE 中 运行 时,我们的应用程序 运行 完美无缺。但是,当我们将其打包为 JAR 时,我们开始看到异常:

SEVERE: Exception NamingException: javax.naming.InvalidNameException: WFNAM00007: Invalid URL scheme name "http-remoting"

我们也尝试过:

http-remoting://127.0.0.1:8080
remoting+http://127.0.0.1:8080

但我们得到了同样的异常。

这是我的代码的主要部分:

private static final String DEFAULT_MESSAGE = "Hello, World!";
private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
private static final String DEFAULT_DESTINATION = "jms/queue/myqueue";
private static final String DEFAULT_MESSAGE_COUNT = "1";
private static final String DEFAULT_USERNAME = "john";
private static final String DEFAULT_PASSWORD = "doe";
private static final String INITIAL_CONTEXT_FACTORY = "org.wildfly.naming.client.WildFlyInitialContextFactory";
private static final String PROVIDER_URL = "http-remoting://127.0.0.1:8080";
Context namingContext = null;

String userName = System.getProperty("username", DEFAULT_USERNAME);
String password = System.getProperty("password", DEFAULT_PASSWORD);

// Set up the namingContext for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
namingContext = new InitialContext(env);

// Perform the JNDI lookups
String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);
log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");
ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);
log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI");

异常发生在这一行:

ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);

这些是 pom.xml 中的依赖项:

<dependency>
   <groupId>org.jboss.eap</groupId>
   <artifactId>wildfly-jms-client-bom</artifactId>
   <version>7.3.4.GA</version>
   <type>pom</type>
</dependency>
<dependency>
   <groupId>org.jboss.eap</groupId>
   <artifactId>wildfly-ejb-client-bom</artifactId>
   <version>7.3.4.GA</version>
   <type>pom</type>
</dependency>
<dependency>
   <groupId>org.jboss.spec.javax.jms</groupId>
   <artifactId>jboss-jms-api_2.0_spec</artifactId>
   <version>1.0.0.Final-redhat-1</version>
</dependency>
<dependency>
   <groupId>commons-io</groupId>
   <artifactId>commons-io</artifactId>
   <version>2.8.0</version>
</dependency>
<dependency>
   <groupId>org.jboss</groupId>
   <artifactId>jboss-ejb-client</artifactId>
   <version>4.0.37.Final</version>
</dependency>
<dependency>
   <groupId>org.wildfly.common</groupId>
   <artifactId>wildfly-common</artifactId>
   <version>1.5.4.Final</version>
</dependency>
<dependency>
   <groupId>org.jboss.remotingjmx</groupId>
   <artifactId>remoting-jmx</artifactId>
   <version>3.0.4.Final</version>
</dependency>

在我看来,您的类路径有重叠 类。我在你的 pom.xml 中看到了同样的事情。这将导致在运行时加载错误的类。

例如,如果您查看 pom.xml of the HelloWorld-JMS 项目,您会发现它 使用了 wildfly-jms-client-bom。事实上,这种“bom”(即物料清单)的全部意义在于将 所有 所需的依赖项合并到一个依赖项中。因此,我建议您只在 pom.xml:

中使用它
<dependency>
   <groupId>org.jboss.eap</groupId>
   <artifactId>wildfly-jms-client-bom</artifactId>
   <version>7.3.4.GA</version>
   <type>pom</type>
</dependency>

同样,在您的应用程序的类路径上,您的类路径(或聚合的等效项)上应该只有 wildfly-jms-client-bom 的依赖项。