简体   繁体   English

如何从命令提示符下运行jar文件

[英]how to run jar files from command prompt

I have executable jar file and want to run from command line along with the environment variable path as a parameter. 我有可执行的jar文件,并希望从命令行运行环境变量路径作为参数。 In eclipse the code is running well by setting up the path variable in eclipse configuration.Please help.The command that i am trying is given below 在eclipse中,通过在eclipse配置中设置path变量,代码运行良好。请帮助。我正在尝试的命令如下

java -jar jar_name java -jar jar_name

java -jar jar_name.jar -DsystemVariableName=value

Access this value in the code as System.getProperty("systemVariableName"); 在代码中以System.getProperty("systemVariableName");访问此值System.getProperty("systemVariableName");

Environment variable can be directly accessed in the code as System.getEnv("EnvVarName"); 可以在代码中以System.getEnv("EnvVarName");形式直接访问环境变量System.getEnv("EnvVarName");

Refer : https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getenv() 参考: https : //docs.oracle.com/javase/7/docs/api/java/lang/System.html#getenv()

您需要执行以下操作:

java -jar <jar-file-name>.jar

java -jar jarfile.jar is the shortest answer possible but note that there are multiple things that maybe need to be set for the jar to run correctly as you may need to specify the Main class or the classpath . java -jar jarfile.jar是可能的最短答案,但请注意,可能需要设置多项操作才能使jar正确运行,因为您可能需要指定Main类或classpath

This Oracle tutorials will help. Oracle教程将有所帮助。

Please see the below link. 请参阅以下链接。 It has all the information you need http://www.wikihow.com/Run-a-.Jar-Java-File . 它包含您需要的所有信息, http://www.wikihow.com/Run-a-.Jar-Java-File

java -jar <jar.file> <parameter> 

您可以定义多个参数。

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

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