使用 Wildfly 模块代替 wildfly-X-client-bom 依赖项

Using Wildfly modules instead of wildfly-X-client-bom dependencies

我有两台 Wildfly 服务器。服务器 A 连接到服务器 B 上的 JMS 主题和 EJB。它们都是 Wildfly 8.2.0.Final.

服务器 A 上的客户端 (a .war) 具有以下 Maven 依赖项:

  <dependency>
     <groupId>org.wildfly</groupId>
     <artifactId>wildfly-ejb-client-bom</artifactId>
     <version>8.2.0.Final</version>
     <type>pom</type>
  </dependency>
  <dependency>
     <groupId>org.wildfly</groupId>
     <artifactId>wildfly-jms-client-bom</artifactId>
     <version>8.2.0.Final</version>
     <type>pom</type>
  </dependency>

是否可以摆脱这些,而只要求在 jboss-deployment-structure.xml 中加载特定的 Wildfly 模块?似乎这些 Maven 依赖项会增加我的 .war.

的大小

谢谢!

编辑:

要查找服务器 B 上的 EJB,我使用此处列出的“1. EJB 客户端库”技术:http://blog.akquinet.de/2014/09/26/jboss-eap-wildfly-three-ways-to-invoke-remote-ejbs/。我的代码与示例非常相似:

Properties prop = new Properties();
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(prop);

并且:

remote.connections=default
remote.connection.default.host=127.0.0.1
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false
remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=${host.auth:JBOSS-LOCAL-USER}

remote.connection.default.username=${username}
remote.connection.default.password=${password}

并且:context.lookup("ejb:/myapp/remote/calculator!de.akquinet.jbosscc.ejb.Calculator");

要连接到我正在使用的服务器 B 上的 JMS 主题:

     final InitialContext initialContext = new InitialContext( m_jndiProperties );
     final ConnectionFactory connectionFactory = getConnectionFactory( initialContext );
     final Connection connection = connectionFactory.createConnection( m_clientKey.getUsername(), m_clientKey.getPassword() );

     try
     {
        final Topic updateTopic = getUpdateTopic( initialContext );
        final TopicSubscriber subscriber;

        if( m_isDurableSubscription )
        {
           connection.setClientID( m_clientKey.getJmsClientId() );
           connection.setExceptionListener( m_exceptionListener );
           final Session subscriberSession = connection.createSession( false, Session.AUTO_ACKNOWLEDGE );
           subscriber = subscriberSession.createDurableSubscriber( updateTopic, m_clientKey.getJmsSubscriptionId() );
        }
        else
        {
           connection.setExceptionListener( m_exceptionListener );
           final Session subscriberSession = connection.createSession( false, Session.AUTO_ACKNOWLEDGE );
           subscriber = ( (TopicSession)subscriberSession ).createSubscriber( updateTopic );
        }

        connection.stop();
        subscriber.setMessageListener( m_msgListener );

        m_connection = connection;

        maybeLogMessage( m_logger, GenericLogLevel.INFO, "Successfully subscribed to topic: '" + topicName + "'." );
     }
     catch( JMSException | NamingException e )
     {
        //noinspection ThrowableResultOfMethodCallIgnored
        JMSCloser.close( connection );
        throw e;
     }

执行这些查找的代码在我的 .war 使用的 Maven 库中。图书馆照常进入 WEB-INF/lib/。

如果您编写标准的 EE 代码,您真的不需要这些。如果您使用标准的 EJB 或 JMS,Wildfly 会自动检测并为您加载模块。

大多数项目应该只需要这个:

<dependency>
    <groupId>org.jboss.spec</groupId>
    <artifactId>jboss-javaee-7.0</artifactId>
    <version>1.0.2.Final</version>
    <scope>provided</scope>
    <type>pom</type>
</dependency>

我能够通过在 jboss-deployment-structure.xml 中添加依赖项来解决这个问题,以便加载额外的 JBoss 个模块。

要成为 EJB 客户端:<module name="org.jboss.remote-naming"/>(您的里程数可能会有所不同,具体取决于您查找 EJB 的方式)。

成为 JMS 客户端:<module name="org.hornetq"/>

这对我有用:

我替换了wildfly-jms-client-bom

<dependency>
    <groupId>org.jboss.eap</groupId>
    <artifactId>wildfly-jms-client-bom</artifactId>
    <version>7.1.0.GA-redhat-11</version>
    <type>pom</type>
</dependency>

javaee-api:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
</dependency>

并添加了对模块org.apache.activemq.artemis的显式依赖(以下最终在war文件中的META-INF/MANIFEST.MF中添加了Dependencies: org.apache.activemq.artemis):

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.3</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <archive>
            <manifestEntries>
                <Dependencies>org.apache.activemq.artemis</Dependencies>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>