使用Wildfly模块而不是wildfly-X-client-bom依赖项

时间:2015-07-24 15:52:09

标签: maven jboss wildfly wildfly-8

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

服务器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 /。

3 个答案:

答案 0 :(得分:0)

如果您编写标准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>

答案 1 :(得分:0)

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

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

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

答案 2 :(得分:0)

这对我有用:

我替换了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的显式依赖(以下内容最终在Dependencies: org.apache.activemq.artemis文件内的META-INF/MANIFEST.MF中添加了war

<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>