How to make a jar file?
Ho开发者_开发知识库w can i make a jar file from both the command line and Netbeans 6.7?
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"/>
jar cf jar-file input-files
http://java.sun.com/developer/Books/javaprogramming/JAR/basics/build.html
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.
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
精彩评论