How to compile multiple java files inside separated package folders recursively


Let say the  folders structure is look like below :

crud

———src

—————-com

————————–yusuf

—————————————controller

——————————————————–UserControler.java

—————————————dao

——————————————————–UserDao.java

—————————————model

——————————————————–User.java

—————————————util

——————————————————–DbUtil.java

———WEB-INF

—————-classes (empty)

Now we need to compile those files then placed class files under classes folder, so the result will shows like this :

 

———classes

—————-com

————————–yusuf

—————————————controller

——————————————————–UserControler.class

—————————————dao

——————————————————–UserDao.class

—————————————model

——————————————————–User.class

—————————————util

——————————————————–DbUtil.class

Here is the javac command to compile those multiple java file resurively :

[yusuf@YusufLaptop src]$ javac -cp $CLASSPATH:../src/ -d ../WEB-INF/classes/ com/*/*/*.java

Explanation

javac                                                    #call java compiler

-cp $CLASSPATH:../src/       #Specify where to find user class files and annotation processors (-classpath)

-d ../WEB-INF/classes/           # Specify where to place generated class files

com/*/*/*.java                              #Target java files

for more help write javac -help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s