(JAVA)使用命令提示符从多个.class文件创建.jar文件 [英] (JAVA) Use Command Prompt to create .jar file from multiple .class files

查看:215
本文介绍了(JAVA)使用命令提示符从多个.class文件创建.jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个.java文件,名为Main.java,并使用Windows命令提示符中的javac编译它。编译器创建多个.class文件(称为Main.class,Main $ 1.class,& Main $ 2.class - 可能是因为我有Main.java文件中的匿名内部类)。我试图创建一个可运行的.jar文件,所以我可以双击一个快捷方式来运行这个应用程序(它是一个Java Swing应用程序),但是我不成功,当我导航到三个类文件的目录并输入:

I have written a .java file, called Main.java, and have compiled it using the javac in the Windows Command Prompt. The compiler is creating multiple .class files (called Main.class, Main$1.class, & Main$2.class--presumably because I have anonymous inner classes in my Main.java file). I am trying to create a runnable .jar file so I can double click a shortcut to run this application (it is a Java Swing application), but I am unsuccessful when I navigate to the directory of the three class files and type:

jar cfv file.jar Main.class Main$1.class Main$2.class

命令提示符然后输出此文本:

The Command Prompt then outputs this text:

added manifest
adding: Main.class(in 4871) (out = 2848)(deflated 41%)
adding: Main$1.class(in 1409) (out = 833)(deflated 40%)
adding: Main$2.class(in 1239) (out = 767)(deflated 38%)

尽管这样,当我在Windows资源管理器中双击file.jar文件,简单地说,没有什么发生。没有摇摆应用程序打开。

Despite this, when I double click on the file.jar file in Windows Explorer, simply put, nothing happens. No swing application opens.

希望有人可以帮助我。谢谢

Hopefully someone can help me out with this. Thank you

最好... SL

推荐答案

使用入口点开关 -e (包含 main()方法的类名) :

You need to use the entry-point switch -e (with the name of the class containing the main() method) as such:

jar cfve file.jar Main Main.class Main$1.class Main$2.class

这篇关于(JAVA)使用命令提示符从多个.class文件创建.jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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