简体   繁体   English

使用-cp运行java程序

[英]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). 这就是我的教授所说的应该工作(他正在使用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. 我在bash提示符〜\\ GroupJsonRPC的基本目录中,〜\\ GroupJsonRPC \\ classes \\ cst420 \\ jsonrpc \\ client \\ GroupServerJavaStub.class中的类文件存在并准备好运行。 The same goes for ~\\GroupJsonRPC\\lib\\json.jar. 〜\\ GroupJsonRPC \\ lib \\ json.jar也是如此。 Any insight into how to get this darn thing running would be greatly appreciated! 任何洞察如何让这个运行的东西运行将非常感谢!

PS: I'm using Windows. PS:我正在使用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 ';' 您需要确保包含类文件的目录以及带有';'的jar文件 separators, and don't use the -jar option. 分隔符,不要使用-jar选项。 It invalidates the -cp option. 它使-cp选项无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用清单文件中的 -cp 选项和类路径运行 java 程序 - run a java program using -cp option and classpath in manifest file 如何在其他 Java 程序中使用 ProcessBuilder 运行 Java 程序。 (使用 -cp 和 -Xbootclasspath 命令) - How to run a Java program using ProcessBuilder inside the other Java program. (with -cp and -Xbootclasspath commands) 使用cp开关编译Java程序-意外行为 - Compiling java program with cp switch - unexpected behavior 线程“ main”中的异常java.io.FileNotFoundException:使用java -cp命令运行Maven项目时 - Exception in thread “main” java.io.FileNotFoundException: when running maven project using java -cp command Java 一起使用“-cp”和“-jar” - Java using “-cp” and “-jar” together 运行java -cp和实现类加载器之间的区别 - Difference between running java -cp and implementing a classloader 在 Docker 中使用“-cp ...”选项运行 Java 应用程序 - running Java application with '-cp ...' option in Docker 使用 -jar 选项运行 java 命令时,您可以使用 -cp 提供额外的库吗? - When running a java command with the -jar option, can you supply additional libraries using -cp? 使用多个文件夹中的包运行java程序 - Running java program using packages in multiple folders 使用Runtime.exec()运行Java程序? - Running a java program using Runtime.exec()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM