I'm puzzled by the process of running java programs, maybe you can help.
I have several .java files in ~/working_dir/org/project/
that have main functions, and I want to package them in a jar to run them. I do:
cd ~/working_dir/org/projectname
javac -classpath $CLASSPATH *.java
cd ~/working_dir/
jar cf myjar.jar org/
And then try to run one of the classes in the jar by doing:
java -cp myjar.jar org.project.SomeClass
and get
Exception in thread "main" java.lang.NoClassDefFoundError: org/project/SomeClass
Could not find the main class: org.project.SomeClass
What do I do wrong? The classes compile without any errors, and jar tf myjar.jar
shows that they're indeed there. As far as I know I don't need to create a Manifest file because I provide the class from which I want to run the main function at runtime - or am I wrong here?
Help much appreciated!