Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling multiple packages using the command line in Java

Hi i have been using an IDE but now I need to run and compile from the command line.

The problem is that I have multiple packages and I have tried to find the answer but nothing has worked.

So I have

src/
  Support/ (.java files)
  Me/ (.java files) 
  Wrapers/ (.java files)  

Do you know how to compile everything with javac?

like image 909
Altober Avatar asked Aug 18 '10 13:08

Altober


People also ask

How do you compile Java files together?

Open a command prompt window and go to the directory where you saved the java program. Assume it's C:\. Type 'javac MyFirstJavaProgram. java' and press enter to compile your code.


1 Answers

The real answer is javac -d (places where classes to be built and placed) -sourcepath (source of the package at the root) -cp (classpath of the dependencies which can again be classes folder where the classes are build and kept) full qualified name of the java file.

Ex javac -d classes -sourcepath src -cp classes src\com\test\FirstSample.java

The FirstSample.java contains the main method. Pacjage structure mentioned below.

Before compiling
HomeApp
--src
------com\test\FirstSample.java (First Sample using the FirstPojo.java)
------com\test\FirstPojo.java
--classes

After compiling
HomeApp
--src
------com\test\FirstSample.java (FirstSample.java using the FirstPojo.java)
------com\test\FirstPojo.java
--classes
------com\test\FirstSample.class (FirstSample.class using the FirstPojo.class)
------com\test\FirstPojo.class

like image 185
pratyush Avatar answered Oct 23 '22 03:10

pratyush