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)).
发布评论
评论(4)
使用 JAR 命令:
使用 Maven:
使用Ant:
Using the JAR command:
Using Maven:
Using Ant:
http://java.sun.com/developer/Books/ javaprogramming/JAR/basics/build.html
http://java.sun.com/developer/Books/javaprogramming/JAR/basics/build.html
命令行:
确保您从与包层次结构匹配的目录的根目录开始
jar
,而不仅仅是包含类文件的目录。目录结构需要与层次结构相匹配。另外,如果您希望 JAR 可执行,则需要包含 MANIFEST.MF 包含一个
Main-class
条目,指定应将哪个类用作入口点(此类必须定义一个public static void main(String[] args)
)。Netbeans:这里是 教程。
Command line:
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 aMain-class
entry specifying which class should be used as the entry point (this class must define apublic static void main(String[] args)
).Netbeans: here is a link to a tutorial.
有很多方法(这里已经回答了足够多的问题),但如果您想要一种非常简单的方法,请查看 Maven。它只是有效:http://maven.apache。 org/guides/getting-started/maven-in-五分钟.html
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