java - class not found problems, aws

i have /aws folder with aws jars and my program Aws

aspectjrt.jar                           
aspectjweaver.jar                       
aws-java-sdk-1.9.23-javadoc.jar         
aws-java-sdk-1.9.23-sources.jar         
aws-java-sdk-1.9.23.jar                 
aws-java-sdk-flow-build-tools-1.9.23.jar
Aws.class                      
commons-codec-1.6.jar          
commons-logging-1.1.3.jar      
freemarker-2.3.18.jar          
httpclient-4.3.jar             
httpcore-4.3.jar               
jackson-annotations-2.3.0.jar  
jackson-core-2.3.2.jar         
jackson-databind-2.3.2.jar     
javax.mail-api-1.4.6.jar       
joda-time-2.2.jar              
namast1.csv                    
spring-beans-3.0.7.jar         
spring-context-3.0.7.jar       
spring-core-3.0.7.jar          

Open in new window


program:

package aws;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.PutObjectRequest;
import java.io.File;
import java.io.IOException;


public class Aws {
    
    private static final String USERNAME = "xxx”;
    private static final String PASSWORD =  "yyy";
    private static final  String  FILEPATH = "/aws/";
   
    private static final String bucketName     = "bucket";
    private static final String keyName        = "name";
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       
        //String fil = args[1];
       // StringBuilder filename =  new StringBuilder(FILEPATH);

        String filename  = "/aws/names.csv";
        
     
  
        File filen = new File(filename.toString());
        
        
        AWSCredentials credentials = new BasicAWSCredentials("xxxx", "yyyy");
        AmazonS3Client clnt = new AmazonS3Client(credentials);
        
        
        try {
         
            System.out.println("Uploading a new object to S3");
         
            
             clnt.putObject(new PutObjectRequest(
            		                bucketName, keyName, filen));
            
        }
        
        catch (AmazonServiceException ase) {
            System.out.println("Caught an AmazonServiceException, which " +
            		"means your request made it " +
                    "to Amazon S3, but was rejected with an error response" +
                    " for some reason.");
            System.out.println("Error Message:    " + ase.getMessage());
            System.out.println("HTTP Status Code: " + ase.getStatusCode());
            System.out.println("AWS Error Code:   " + ase.getErrorCode());
            System.out.println("Error Type:       " + ase.getErrorType());
            System.out.println("Request ID:       " + ase.getRequestId());
        } catch (AmazonClientException ace) {
            System.out.println("Caught an AmazonClientException, which " +
            		"means the client encountered " +
                    "an internal error while trying to " +
                    "communicate with S3, " +
                    "such as not being able to access the network.");
            System.out.println("Error Message: " + ace.getMessage());
        }
        
        
            
        
        // TODO code application logic here
    }
    
}

Open in new window



when calling the program:

java aws.Aws

i'm getting an error:

Exception in thread "main" java.lang.NoClassDefFoundError: com.amazonaws.auth.AWSCredentials       
        at java.lang.J9VMInternals.verifyImpl(Native Method)                                       
        at java.lang.J9VMInternals.verify(J9VMInternals.java:94)                                   
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:171)                              
Caused by: java.lang.ClassNotFoundException: com.amazonaws.auth.AWSCredentials                     
        at java.net.URLClassLoader.findClass(URLClassLoader.java:434)                              
        at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:703)                             
        at java.lang.ClassLoader.loadClass(ClassLoader.java:682)                                   
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)                           
        at java.lang.ClassLoader.loadClass(ClassLoader.java:665)                                   

Open in new window


classpath is

.:/aws
snigerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sathish David Kumar NArchitectCommented:
can you check aws sdk jar are in classpath or not
0
Phil PhillipsDevOps ArchitectCommented:
You may want make sure your classpath has /aws/* (not just /aws)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzynxSr. Software engineerCommented:
Reason of the error:
The class
com.amazonaws.auth.AWSCredentials

Open in new window

is somewhere in a jar file that is not in your Java's class path. Hence it can't find that class.
More info on class path: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
0
CEHJCommented:
String filename  = "/aws/names.csv";

Open in new window


change to

System.out.println(System.getProperty("java.class.path"));
String filename  = "/aws/names.csv";

Open in new window


and post result please
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.