使用命令行参数运行jar文件 [英] Run jar file with command line arguments

查看:218
本文介绍了使用命令行参数运行jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在命令提示符下运行jar文件并将参数传递给它。

How can I run a jar file in command prompt and pass arguments to it.

ie: test.jar -get 将在命令提示符/终端中输入

ie: "test.jar -get" would be entered in command prompt/terminal

推荐答案

对于问题


如何在命令提示符下运行jar文件,但带参数

How can i run a jar file in command prompt but with arguments

在执行时将参数传递给jar文件

To pass arguments to the jar file at the time of execution

java -jar myjar.jar arg1 arg2

在Main-Class的main()方法中您的JAR文件中的[manifest.mft文件中提到]。你可以像这样检索它们:

In the main() method of "Main-Class" [mentioned in the manifest.mft file]of your JAR file. you can retrieve them like this:

String arg1 = args[0];
String arg2 = args[1];

这篇关于使用命令行参数运行jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆