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?
 
Phil PhillipsDirector of DevOps & Quality AssuranceCommented:
You may want make sure your classpath has /aws/* (not just /aws)
0
 
Sathish David Kumar NArchitectCommented:
can you check aws sdk jar are in classpath or not
0
 
zzynxSoftware 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.