简体   繁体   中英

How to compile set of java files in different packages and then build .jar file using command line?

I have set of .java files in different packages. For example,

src |- Main.java |- pkg1 |- pkg2 |- A.java |- B.java |- C.java |- pkg3 |- pkg4 |- D.java |- E.java

How can I compile all these .java files and then build the .jar library using command line in Windows platform ?

You should really use an IDE, its much easier and more productive. It can be done:

javac Main.java pkg1\pkg2\A.java pkg1\pkg2\B.java pkg1\pkg2\C.java pkg3\pkg4\D.java pkg3\pkg4\E.java
jar -cf my.jar  *.class pkg1 pkg3

That will not have a manifest so it won't be executable.

To make it executable, you need to pick a Main class and create a file named manifest.txt with a text editor:

Manifest-Version: 1.0
Main-Class: Main

and make the jar with this:

 jar -cmf manifest.txt my.jar  *.class pkg1 pkg3

Another option is Apache ANT . See their tutorial to get started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM