I haven't used Java in a long while but I am trying to write a simple Java application which utilizes the AWS API.
The part I am stuck at is that I can't exactly remember how to link the API to the Java code. I am not using eclipse and I don't want to, I like writing my code in just sublime text. So I really need someone to explain to me how to link it all together in simple terms.
My file hierarchy is:
- Project
- Test.java
- aws-java-sdk-1.10.5.1.jar
- aws-java-sdk-1.10.5.1
- Documentation
- lib
- aws-java-sdk-1.10.5.1-javadoc.jar
- aws-java-sdk-1.10.5.1-sources.jar
- aws-java-sdk-1.10.5.1.jar
- aws-java-sdk-flow-build-tools-1.10.5.1.jar
- samples
- third-party
I moved aws-java-sdk-1.10.5.1.jar out of the lib folder and put it on the same level of my source code because that's what I thought I needed to do. For source code, Here is a sample of what I have:
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.sns.AmazonSNSClient;
public class Test
{
public static void main(String args[])
{
BasicAWSCredentials cruds = new BasicAWSCredentials("<<ACCESS KEY>>", "<<SECRET KEY>>");
AmazonSNSClient snsClient = new AmazonSNSClient(cruds);
System.out.println("Hello World!");
}
}
In my terminal, I compile my code by using the command:
javac Test.java
however that doesn't work for me and I get the error: cannot find symbol error. I manage to get it to compile by using the following command. (But i feel like the top command should work if my hierarchy is correct?):
javac -cp aws-java-sdk-1.10.5.1.jar Test.java
After I compile the code and get my class file, I try to run my program with the command
java Test
but that throws me the stacktrace of
Exception in thread "main" java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
at java.lang.Class.getMethod0(Class.java:2937)
at java.lang.Class.getMethod(Class.java:1771)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.amazonaws.auth.AWSCredentials
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
I am sure this is an extremely stupid problem and it’s mostly me not being able to remember how to use this correctly. If someone can give me an idiots guide on how to make this work, I would be so thankful to you!