在另一个目录中运行包含源文件的jar文件

时间:2022-06-22 02:23:09

I would like to run a jar file right from the command line without having to put the jar file in the directory containing my input files. Any ideas on how I can do this if it is possible?

我想直接从命令行运行一个jar文件,而不必将jar文件放在包含我的输入文件的目录中。如果可能的话,有关如何做到这一点的任何想法?

1 个解决方案

#1


Wouldn't you just supply a class path argument when executing the class inside of the JAR? For example:

在JAR中执行类时,您是否只提供类路径参数?例如:

java -cp lib/somejar.jar org.foo.bar.MyClass

java -cp lib / somejar.jar org.foo.bar.MyClass

Where -cp is the classpath argument and lib/somejar.jar is the path to the jar you are trying to execute.

其中-cp是classpath参数,lib / somejar.jar是您尝试执行的jar的路径。

I'm not sure I'm clear on what you're looking for.

我不确定我对你要找的东西很清楚。

#1


Wouldn't you just supply a class path argument when executing the class inside of the JAR? For example:

在JAR中执行类时,您是否只提供类路径参数?例如:

java -cp lib/somejar.jar org.foo.bar.MyClass

java -cp lib / somejar.jar org.foo.bar.MyClass

Where -cp is the classpath argument and lib/somejar.jar is the path to the jar you are trying to execute.

其中-cp是classpath参数,lib / somejar.jar是您尝试执行的jar的路径。

I'm not sure I'm clear on what you're looking for.

我不确定我对你要找的东西很清楚。