I am having problems using the new AmazonAWS SDK in a JBoss AS 7.1 (EE6) project
I am just using the S3 library, so in accordance with the new release (1.9.7) I am only using the s3, core, kms jars
-aws-java-sdk-core-1.9.17.jar
-aws-java-sdk-s3-1.9.17.jar
-aws-java-sdk-kms-1.9.17.jar
So I have created 3 separate module.xml entries for each jar within the /com/amazonaws directory:
/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>
(I have put the extra dependencies eg. apache-commons, jodatime etc. directly in the module directory)
The following jboss-deployment-structure.xml entry:
<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>
(I have also tried declaring these as EAR-level dependancies with export=true)
The the following pom.xml entry:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.9.17</version>
<scope>provided</scope>
</dependency>
But whenever I try to initialise a new S3 client:
AWSCredentials credentials = new ProfileCredentialsProvider("ProcessingApp").getCredentials();
AmazonS3 s3 = new AmazonS3Client(credentials);
I get the following exception:
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
My hunch would be a conflict with apache-commons-logging as there is an import in the SdkMBeanRegistrySupport class and I know JBoss uses this library elsewhere using an alias to org.slf4j.jcl-over-slf4j, but I thought that putting the apache lib in with the jar would sort this out?
I am fairly new to AS7 so maybe I'm missing a trick?
Ok I got eventually thanks to @Federico Sierra, here is the sdk-core module.xml (nb. I had to drop the commons-logging, httpclient and httpcore jars into the module folder as the ones shipped with JBoss arent compatible, I added the jackson and joda libs as their own modules)...
<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>
and the sdk-s3 module.xml needed javax.xml.stream.api too
<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>
Hope this helps someone else