Hey I have a question about running an application that uses a .jar file. If I have a file outside called Tester.java that uses a jar file, let's call it myJar.jar, and let's say the classes are packaged as myPackage.myClasses. I imported all the classes I needed using

import myPackage.myClasses.className;

in Tester.java, and when I go to compile it I typed

javac -cp ./:myJar.jar

myJar is in the same directory as my Tester.java file
Then to execute it i typed

java -cp ./:myJar.jar

and I got a

java.lang.ClassNotFoundException(wrong name: myPackage/myClasses/Tester)

It seems like it is looking inside the jar file for the Tester class, when it is in my current directory. How do I get it to execute the Tester class? Any help would be appreciated

7 Years
Discussion Span
Last Post by peter_budo

yeah i looked at that yesterday and I couldn't figure it out.

That will be because that tutorial is dedicated to creating JAR file for your application, updating JAR and executing it. It does not describe how to execute application that requires a library through command line.
This can be done as

java -cp /library/location/name.jar:/some/other/path.jar com.your.main.classname
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.