JBoss AS7上的AWS Java SDK - module.xml条目

时间:2015-02-16 18:05:48

标签: maven amazon-web-services jboss jboss7.x java-ee-6

我在JBoss AS 7.1(EE6)项目中使用新的AmazonAWS SDK时遇到问题

我只是使用S3库,所以按照新版本(1.9.7)我只使用s3,core,kms jar

-aws-java-sdk-core-1.9.17.jar
-aws-java-sdk-s3-1.9.17.jar
-aws-java-sdk-kms-1.9.17.jar

所以我在/ com / amazonaws目录中为每个jar创建了3个单独的module.xml条目:

/com/amazonaws/aws-java-sdk-s3/main/module.xml

<module xmlns="urn:jboss:module:1.1" name="com.amazonaws.aws-java-sdk-s3">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>

    <resources>
        <resource-root path="aws-java-sdk-s3-1.9.17.jar"/>
        <!-- Insert resources here -->
    </resources>

    <dependencies>
        <module name="com.amazonaws.aws-java-sdk-core" />
        <module name="com.amazonaws.aws-java-sdk-kms" />
    </dependencies>
</module>

/com/amazonaws/aws-java-sdk-kms/main/module.xml

                  

<resources>
    <resource-root path="aws-java-sdk-kms-1.9.17.jar"/>
    <!-- Insert resources here -->
</resources>

<dependencies>
    <module name="com.amazonaws.aws-java-sdk-core" />
</dependencies>

/com/amazonaws/aws-java-sdk-core/main/module.xml

<module xmlns="urn:jboss:module:1.1" name="com.amazonaws.aws-java-sdk-core">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>

    <resources>
        <resource-root path="aws-java-sdk-core-1.9.17.jar"/>
        <resource-root path="commons-logging-1.1.3.jar"/>
        <resource-root path="httpclient-4.3.4.jar"/>
        <resource-root path="jackson-databind-2.3.2.jar"/>
        <resource-root path="joda-time-2.2.jar"/>

        <!-- Insert resources here -->
    </resources>

</module>

(我已将额外的依赖项,例如.apache-commons,jodatime等直接放在模块目录中)

以下jboss-deployment-structure.xml条目:

  <sub-deployment name="Processor-ejb.jar">
    <dependencies>
        <module name="com.amazonaws.aws-java-sdk-core" />
        <module name="com.amazonaws.aws-java-sdk-s3" />
        <module name="com.amazonaws.aws-java-sdk-kms" />

    </dependencies>
  </sub-deployment>

(我也尝试将这些声明为具有export = true的EAR级别依赖项)

以下pom.xml条目:

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-s3</artifactId>
    <version>1.9.17</version>
    <scope>provided</scope>
</dependency>

但每当我尝试初始化一个新的S3客户端时:

AWSCredentials credentials = new ProfileCredentialsProvider("ProcessingApp").getCredentials();
AmazonS3 s3 = new AmazonS3Client(credentials);

我得到以下异常:

Caused by: java.lang.NoClassDefFoundError: javax/management/MalformedObjectNameException
    at com.amazonaws.jmx.SdkMBeanRegistrySupport.registerMetricAdminMBean(SdkMBeanRegistrySupport.java:27)
    at com.amazonaws.metrics.AwsSdkMetrics.registerMetricAdminMBean(AwsSdkMetrics.java:330)
    at com.amazonaws.metrics.AwsSdkMetrics.<clinit>(AwsSdkMetrics.java:308)
    at com.amazonaws.services.s3.AmazonS3Client.<clinit>(AmazonS3Client.java:261)
    at net.processor.actions.scheduled.ScheduledActionsBean.minuteActions(ScheduledActionsBean.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [classes.jar:1.6.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [classes.jar:1.6.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [classes.jar:1.6.0_65]
    at java.lang.reflect.Method.invoke(Method.java:597) [classes.jar:1.6.0_65]
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
    at org.jboss.seam.intercept.Interceptor.aroundTimeout(Interceptor.java:201)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:74)
    at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:79)
    ... 56 more

我的预感与apache-commons-logging有冲突,因为在SdkMBeanRegistrySupport类中有一个导入,我知道JBoss在别处使用org.slf4j.jcl-over-slf4j的别名,但我认为将apache lib放入jar中可以解决这个问题吗?

我对AS7相当新,所以也许我错过了一个技巧?

2 个答案:

答案 0 :(得分:1)

好的,我最终感谢@Federico Sierra,这里是sdk-core module.xml(nb。我不得不将commons-logging,httpclient和httpcore jar放入模块文件夹,因为JBoss附带的不兼容,我添加了jackson和joda libs作为他们自己的模块)...

<module xmlns="urn:jboss:module:1.1" name="com.amazonaws.aws-java-sdk-core">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>

    <resources>
        <resource-root path="aws-java-sdk-core-1.9.17.jar"/>
        <resource-root path="commons-logging-1.1.3.jar"/>
        <resource-root path="httpclient-4.3.4.jar"/>
        <resource-root path="httpcore-4.3.2.jar"/>
        <!-- Insert resources here -->
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.xml.stream.api"/>
        <module name="javax.xml.bind.api"/>
        <module name="com.fasterxml.jackson"/>
        <module name="org.joda.time"/>
    </dependencies>

</module>

并且sdk-s3 module.xml也需要javax.xml.stream.api

                  

<resources>
    <resource-root path="aws-java-sdk-s3-1.9.17.jar"/>
    <!-- Insert resources here -->
</resources>

<dependencies>
    <module name="com.amazonaws.aws-java-sdk-core" />
    <module name="com.amazonaws.aws-java-sdk-kms" />
    <module name="javax.xml.stream.api"/>
</dependencies>

希望这有助于其他人

答案 1 :(得分:0)

我想分享我的代码,它对我有用,我希望它对你有用

<module xmlns="urn:jboss:module:1.5" name="com.amazonaws.aws-java-sdk-s3">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>

    <resources>
        <resource-root path="aws-java-sdk-s3-1.11.106.jar"/>
        <resource-root path="aws-java-sdk-core-1.11.106.jar"/>
        <resource-root path="aws-java-sdk-kms-1.11.106.jar"/>
        <resource-root path="jmespath-java-1.11.106.jar"/>
        <resource-root path="commons-logging-1.1.1.jar"/>
        <resource-root path="httpclient-4.5.2.redhat-1.jar"/>
        <resource-root path="httpcore-4.4.4.redhat-1.jar"/>
        <resource-root path="jackson-annotations-2.8.9.redhat-1.jar"/>
        <resource-root path="jackson-databind-2.8.9.redhat-1.jar"/>
        <resource-root path="jackson-core-2.8.9.redhat-1.jar"/>
        <resource-root path="jackson-dataformat-cbor-2.6.6.jar"/>
    </resources>

    <dependencies>
        <module name="javax.api"/>
        <module name="javax.xml.bind.api"/>
        <module name="javax.xml.stream.api"/>
        <module name="org.joda.time"/>
    </dependencies>
</module>

我只使用一个文件夹&#34; com / amazonaws / aws-java-sdk-s3&#34;在jboss y我放了所有的罐子。