How to make a jar file?

依然范特西╮ 提交于 2019-12-12 10:09:04

问题


How can i make a jar file from both the command line and Netbeans 6.7?


回答1:


Using the JAR command:

jar cf jar-file input-file(s)

Using Maven:

<packaging>jar</packaging>

Using Ant:

 <jar destfile="${dist}/lib/app.jar" basedir="${build}/classes"/>



回答2:


jar cf jar-file input-files

http://java.sun.com/developer/Books/javaprogramming/JAR/basics/build.html




回答3:


Command line:

jar cf jarfile [ -C dir ] inputfiles

Make sure you are jar-ing from the root of the directory matching your package hierarchy, rather than just the directory with the class files. The directory structure needs to match the hierarchy.

Also, if you want the JAR to be executable, you need to include a MANIFEST.MF containing a Main-class entry specifying which class should be used as the entry point (this class must define a public static void main(String[] args)).

Netbeans: here is a link to a tutorial.




回答4:


There are many ways (enough already answered here), but if you want a REALLY SIMPLE way, look at Maven. It just works: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html



来源:https://stackoverflow.com/questions/2179113/how-to-make-a-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!