如何获得Java程序的可执行文件? [英] How can I get an executable file of a Java program?
问题描述
可能重复:
如何将Java程序转换为.exe文件?
我正在尝试将用Java 6编写的程序导出到JAR文件.
I'm trying to export a program written in Java 6 to a JAR file.
我的项目包含一个Internet上的Java库和一些Java源文件.创建JAR文件时,默认情况下应设置类路径,并且最终用户应能够直接从命令提示符或其他来源运行项目.
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.
如果可以的话,我的目标是将所有内容导出到JAR文件.另外,程序输出应在命令提示符下给出.
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?
推荐答案
为此,您需要编写一个 META-INF/MANIFEST.MF
文件;该文件应位于您要分发的jar文件中(即人们与 java -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
要关注的主要字段是 Main-Class
(用于指定要查找 main
方法的类)和 Class-Path
(指定您正在使用的外部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).
这篇关于如何获得Java程序的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!