6 Replies Latest reply on Feb 14, 2014 11:25 AM by spolti

    Class not found when instantiating AmazonS3Client on Jboss 7

    toriacht

      I am trying to run some simple Amazon AWS S3 example code on JBoss. It runs fine as a JSE app. I add the same amazon dependency to my POM in both JSE and JEE6 projects. The call to instantiate the client always throws an exception when running it on JBoss

      AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

      AmazonS3 conn = new AmazonS3Client(credentials); << this call here

      Throws this exception:

      NoClassDefFoundError: org/apache/http/conn/scheme/SchemeSocketFactory

      I think this is related to the http-client.jar but I have no idea how to fix this, tell JBoss where to pick up the correct dependency etc?

      ref: http://aws.amazon.com/developers/getting-started/java/

       

      I basically moved some of that sample code to a method call and try to and make the connection to S3

       

      Thanks

        • 1. Re: Class not found when instantiating AmazonS3Client on Jboss 7
          spolti

          Put thiis into your pom.xml and build the app again:

           

          <dependency>

            <groupId>org.apache.httpcomponents</groupId>

            <artifactId>httpclient</artifactId>

            <version>4.1-alpha2</version>

            </dependency>

           

          Rgz

          • 2. Re: Class not found when instantiating AmazonS3Client on Jboss 7
            toriacht

            Hi Filippe,

             

            Thank you for the reply, if I add that to the POM or even 4.1.2 as a dependency it is still the same issue. The httpclient-4.1.2 alrteady exists in {jboss-home}/modules/org/apache/httpcomponents but for some reason the application can;t find it

             

            /T

            • 3. Re: Class not found when instantiating AmazonS3Client on Jboss 7
              sfcoy

              Just because you can see a jar in the JBossAS distribution does not mean that your application can see it. JBossAS 7.x and WildFly (for the most part) only expose the classes and interfaces that the JavaEE specs  specify.

               

              You can use a jboss-deployment-structure.xml file to import it into your application, but you're probably better off providing your own copy in the WEB-INF/lib directory or EAR/lib directory as appropriate.

              • 4. Re: Class not found when instantiating AmazonS3Client on Jboss 7
                vbchin2

                Not all the modules (associated JARs) are loaded as the server boots up and nor are they loaded just because there is API call in your WAR. You must explicitly mention which module your WAR depends on using the methods described here. You can either choose to add/modify:

                1. MANIFEST.MF
                2. jboss-deployment-structure.xml (as suggested by Stephen)

                 

                One thing I wouldn't recommend (if and only if JBoss Application Server is your deployment platform) is packaging it again within your WAR as it is already provided by the container as a module.

                1 of 1 people found this helpful
                • 5. Re: Class not found when instantiating AmazonS3Client on Jboss 7
                  toriacht

                  Thanks for the replies guys...So something like below should to the trick to include all classes in the jar?

                   

                   

                  Manifest-Version: 1.0
                  Class-Path: httpclient-4.1.2.jar 
                  

                  or

                  in my MainApp.war META-INF/ a jboss-deployment-structure.xml like this:

                   

                  <jboss-deployment-structure>
                    <sub-deployment name="myMavenModule.jar">
                    <dependencies>
                    <module name="org.apache.httpcomponents" />
                    </dependencies>
                    </sub-deployment>
                  </jboss-deployment-structure>
                  
                  • 6. Re: Class not found when instantiating AmazonS3Client on Jboss 7
                    spolti

                    Yes, if the jar is under JBOSS/modules you must have a explicit dependency inside your app using Manifest or jboss-deployment-structure.xml, but the jboss-deployment-structure.xml must be under WEF-INF floder, not META-INF , like scoy sayd.

                    1 of 1 people found this helpful