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

Recommended Answers

All 3 Replies

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.