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

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

问题描述

我编写了一个名为 Main.java 的 .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 文件时,简单地说,没有任何反应.没有打开 Swing 应用程序.

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天全站免登陆