Creating an Executable jar File
来源:互联网 发布:哔哩哔哩网站源码 编辑:程序博客网 时间:2024/06/05 00:18
In Java, it is common to combine several classes in one .jar ("java archive") file. Library classes are stored that way. Larger projects (such as the Case Study in the AP program) use jar files. You can create your own jar file combining several classes, too.
jar files are created using the jar.exe utility program from JDK. You can make your jar file runnable by telling jar.exe which class has main. To do that, you first need to create a manifest file. A manifest is a one-line text file with a "Main-Class" directive.
For example:Main-Class: DanceStudio
This line must end with a newline.
A jar file created with a main class manifest can be used both as a library and a runnable jar. If you use it as a library, you can edit and compile any of the classes included in the jar, and add it to your project. Then it will override the one in the jar file.
You can create a manifest file in any text editor, or even by using the MS-DOS echo command. You can give your manifest file any name, but it’s better to use something standard, such as manifest.txt.
Once you have a manifest and all your classes have been compiled, you need to run JDK’s jar.exe utility. It is located in the JDK’s bin folder, the same place where javac.exe and java.exe. are. jar.exe takes command-line arguments; if you run it without any arguments, it will display the usage information and examples.
You need C\mywork> jar cvfm MyJarName.jar manifest.txt *.class
cvfm means "create a jar; show verbose output; specify the output jar file name; specify the manifest file name." This is followed by the name you wish to give to your jar file, the name of your manifest file, and the list of .class files that you want included in the jar. *.class means all class files in the current directory.
Creating a jar File in Command Prompt
Start Command Prompt.
Navigate to the folder that holds your class files:
C:\>cd \mywork
Set path to include JDK’s bin. For example:
C:\mywork> path c:\Program Files\Java\jdk1.5.0_09\bin;%path%
Compile your class(es):
C:\mywork> javac *.java
Create a manifest file:
C:\mywork> echo Main-Class: DanceStudio >manifest.txt
Create a jar file:
C:\mywork> jar cvfm DanceStudio.jar manifest.txt *.class
Test your jar:
C:\mywork> DanceStudio.jar
- Creating an Executable jar File
- Creating an Executable jar File
- gcc is unable to create an executable file
- creating a Self Deleting Executable
- An executable Python app
- move resource files like logback.xml for packaging an executable jar
- An In-Depth Look into the Win32 Portable Executable File Format
- An In-Depth Look into the Win32 Portable Executable File Format
- An In-Depth Look into the Win32 Portable Executable File Format, Part 2
- An In-Depth Look into the Win32 Portable Executable File Format
- 【转】An In-Depth Look into the Win32 Portable Executable File Format
- An In-Depth Look into the Win32 Portable Executable File Format, Part 2
- windows编译ffmpeg出现gcc is unable to create an executable file 的一般情况
- windows编译ffmpeg出现gcc is unable to create an executable file 的一般情况
- ubuntu14.04交叉编译ffmpeg出现unable to create an executable file. C compiler test failed.
- Portable Executable FILE FORMAT
- Creating an LLVM Project
- Creating an HMAC CryptCreateHash()
- 帮助业务人员解读Larry Ellison的会议成果
- net_jQuery_50个必备的实用jQuery代码段
- VC大讲堂_体会
- 编程思想要靠有效的实践去获得
- 浅析DirectShow音视频同步解决方案
- Creating an Executable jar File
- android TextView改变alpha的方法
- Objective-C Autorelease Pools(自动释放池)
- 2011级-csdn-java-张侃— Hibernate原理与应用(二)
- 从C#到Python —— 1 变量和数据类型
- JAVA string常用的操作
- 在MyEclipse中编辑XML没有智能提示的问题
- execute、executeQuery和executeUpdate之间的区别
- Makefile文件字符串处理函数subst使用