问题
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