1

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 ?

1
  • 3
    Read the documentation of javac (the compiler), and jar (the archiver), and you'll eventually need java (to run the code). Commented Aug 26, 2015 at 22:35

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

I can't use and ide for this. I have to do it manually. I have to grab the files in the directory and compile and then build the jar through a scheduled process..
I've found much easier way to compile using a batch file with the command, for /r %%a in (*.java) do ( javac "%%a" ). Created the .jar file using your command. Thanks for the help :)
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.