简体   繁体   中英

Running a java program using -cp

so I've checked many posts here and tried everything people suggested and I'm still getting "Could not find or load main class" error, and my professor wasn't very helpful in his answer when I asked for help.

This is what my professor said is supposed to work (he is using OSX).

java -cp classes:lib/json.jar cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080

After reading some other posts on this site, I also tried:

java -cp classes:"lib/json.jar" cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080
java -cp "lib/json.jar" cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080

Still nothing works. I'm in the base directory in a bash prompt ~\\GroupJsonRPC and the class file that is in ~\\GroupJsonRPC\\classes\\cst420\\jsonrpc\\client\\GroupServerJavaStub.class exists and is ready for running. The same goes for ~\\GroupJsonRPC\\lib\\json.jar. Any insight into how to get this darn thing running would be greatly appreciated!

PS: I'm using Windows.

The proper command is:

java -cp "classes;lib/json.jar" cst420.jsonrpc.client.GroupServerJavaStub http://127.0.0.1:8080

You need to be sure to include the directory of your class files as well as the jar file(s) with ';' separators, and don't use the -jar option. It invalidates the -cp option.

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