简体   繁体   中英

Error running .jar on a Mac

I have 2 files, Project.jar and JavaFile.java, saved in a folder called Project. I compiled them both successfully using Mac's Terminal as per below:

 javac -cp Project.jar JavaFile.java

However, after trying to run the program, which is supposed to receive 2 arguments, using

 java -cp Project.jar JavaFile argument1 argument2

I get the following error message:

Exception in thread "main" java.lang.NoClassDefFoundError: JavaFile
Caused by: java.lang.ClassNotFoundException: JavaFile
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

I'm very new to Java and any help would be much appreciated.

Thanks!

Ok, so I figured it out... I need to use colon in order to separate the elements:

javac -cp "Project.jar:" JavaFile.java

java -cp "Project.jar:" JavaFile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM