从 Eclipse 导出 java jar 帮助
所以我有一个只有一个类 Main: 的项目
public class Main{
public static void main(String[] args) {
System.out.println("asdf");
System.out.println(args[0]);
System.out.println(Integer.parseInt(args[1]));
}
}
,所以我尝试将其导出为一个独立的 jar...这就是我
- 为该项目创建的运行配置...运行配置从 eclipse 正常运行...它打印参数就好了...
- 右键单击项目,选择导出,
- 选择可运行的 jar 文件选项,
- 选择我之前创建的运行配置作为运行配置,选择导出目标,按完成等,
但是当我从命令行运行程序时:
Main.jar "testtest" 123
什么也没发生......它没有打印出参数......也没有打印出我在 main() 函数中指定的“asdf”...
我做错了什么?
so I have a project that only has one class Main:
public class Main{
public static void main(String[] args) {
System.out.println("asdf");
System.out.println(args[0]);
System.out.println(Integer.parseInt(args[1]));
}
}
so I tried to export this as a standalone jar...here's what I did
- created a run configuration for the project...the run configuration runs properly from eclipse...it prints the arguments just fine...
- right click on the project, selected export
- choose the runnable jar file option
- selected my previously created run configuration as the run configuration, chose export destination press finish, etc
but then when I run the program from the commandline:
Main.jar "testtest" 123
nothing came up.....it didn't print out the arguments....nor did it print out the "asdf" I specified in the main() function...
what did I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
运行 java -jar Main.jar "testtest" 123 ?
Run
java -jar Main.jar "testtest" 123
?我认为您误解了导出为可运行 jar 的含义:这不会创建可执行文件。它只是创建一个存档文件,其中包含所有已编译的类以及一些有关在使用 java -jar JARNAME 调用时运行哪个类的特殊元信息。
请注意,这也意味着程序的所有用户仍然需要安装 java 运行时。
I think you are getting wrong what exporting as a runnable jar means: This does not create an executable file. It just creates an archived file with all your compiled classes and some special meta information about which class to run when invoked with
java -jar JARNAME
.Note that this also means all users of your program still need to have a java runtime installed.