[英]how to run a java class in another folder with jar file
i'd like to run a java class on other folder, i have a mysqlcon.jar on the current path and a PetsGUI.class on ./classes/ 我想在其他文件夹上运行一个Java类,在当前路径上有一个mysqlcon.jar,在./classes/上有一个PetsGUI.class
when i try to run it by doing 当我尝试通过运行它
java -cp .:mysqlcon.jar -d classes/PetsGUI
i receive 我收到
classes/PetsGUI not found
if i move mysqlcon.jar on classes and type 如果我在类上移动mysqlcon.jar并输入
java -cp .:mysqlcon.jar PetsGUI
on classes/ it runs, so the code is correct. 在类上/它运行,因此代码正确。 what's the correct command to run it?
什么是运行它的正确命令?
So you need the jar file, and the classes directory in the classpath: 因此,您需要jar文件和classpath中的classes目录:
java -cp ./classes:mysqlcon.jar PetsGUI
java doesn't expect a file path as argument. Java不希望将文件路径作为参数。 It expects the fully quelified name of a class.
它需要一个类的完全查询的名称。 And that class is then searched on the classpath.
然后在类路径中搜索该类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.