如何获得Java程序的可执行文件?

发布于 2024-07-17 03:57:26 字数 437 浏览 4 评论 0原文

可能的重复:
如何将我的 java 程序转换为 . exe 文件?

我正在尝试将用 Java 6 编写的程序导出到 JAR 文件。

我的项目包含一个来自 Internet 的 Java 库和一些 Java 源文件。 当我创建 JAR 文件时,应该默认设置类路径,并且最终用户应该能够直接从命令提示符或其他源运行项目。

我的目标是将所有内容导出到 JAR 文件(如果可能的话)。 此外,程序输出应该在命令提示符处给出。

我怎样才能以这种方式导出我的程序?

Possible Duplicate:
How can I convert my java program to an .exe file ?

I'm trying to export a program written in Java 6 to a JAR file.

My project contains one Java library from the Internet and some Java source files. When I create the JAR file, the classpath should be set by default and the end-user should be able to run the project directly from either the command prompt or some other source.

My goal is to export everything to a JAR file, if that's possible. Also, the program output should be given at the command prompt.

How can I export my program in this way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仙女山的月亮 2024-07-24 03:57:26

您需要为此编写一个 META-INF/MANIFEST.MF 文件; 该文件应该位于您正在分发的 jar 文件中(即人们与 java -jar 一起使用的文件)。 这是我最近编写的一个“项目”的示例:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 11.3-b02 (Sun Microsystems Inc.)
Main-Class: com.hedgee.simonsays.Main
Class-Path: lib/libthrift.jar

需要关心的主要字段是 Main-Class(它指定要查找 main 方法的类),以及Class-Path(指定您正在使用的外部 jar 文件)。

You need to write a META-INF/MANIFEST.MF file for this; the file should sit within the jar file you're distributing (i.e., the one that people use with java -jar). Here's an example for a recent "project" I wrote:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 11.3-b02 (Sun Microsystems Inc.)
Main-Class: com.hedgee.simonsays.Main
Class-Path: lib/libthrift.jar

The main fields to care about are Main-Class (which specifies which class to look for your main method), and Class-Path (which specifies the external jar files you're using).

滴情不沾 2024-07-24 03:57:26

您可以使用 Jsmooth http://jsmooth.sourceforge.net/ 捆绑您的 java 代码以生成可执行文件。

You can use Jsmooth http://jsmooth.sourceforge.net/ to bundle your java code to make an executable.

忆梦 2024-07-24 03:57:26

我对两种不同的方法有很好的经验:

1)使用 fatjar 插件和 eclipse 来创建一个包含您需要嵌入的所有 jar 的单个 jar 文件(使用自定义类加载器)。 这将创建一个可单击的 jar 文件(如果它是 GUI 程序)。 如果您需要此 Jar 的控制台输出,请按照 Bhushan 的描述用 jsmooth 包装它。

2) 使用 Eclipse 3.5 Milestone 6 中的“Export -> Runnable Jar”和“将依赖库复制到子文件夹”选项来创建一个普通的可运行 jar,其中包含引用依赖 jar 文件(放入子文件夹中)的正确清单)。 如果您想要一个不使用任何技巧的解决方案,这非常有效,但编写脚本有点困难。

I have had good experiences with two different approaches:

1) Use the fatjar plugin with eclipse to create a single jar file with all the jars you need embedded (uses a custom classloader). This creates a clickable jar file (if it is a GUI program). If you need console output for this Jar wrap it with jsmooth as described by Bhushan.

2) Use the "Export -> Runnable Jar" in Eclipse 3.5 Milestone 6 with the "copy dependent libraries to a subfolder" option to create an ordinary runnable jar with a proper manifest referencing the dependent jar files (which are put in a subfolder). This works very well if you want a solution not using any tricks, but it is a bit hard to script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文