Compiling all modified Java files in a folder on Unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compiling all modified Java files in a folder on Unix
# 1  
Old 04-13-2010
Question Compiling all modified Java files in a folder on Unix

Hi all,

I have a Unix script that will compile all Java files in a sub folder as follows:

find . -name "*.java" -print -exec $JAVA_HOME/bin/javac -cp .:$CLASSPATH '{}' \;

I would like to enhance it to only compile those Java files who:

1.) Have no class file
2.) Have a class file modified in the past.

Could someone please assist me with this? Thanks for any help.
# 2  
Old 04-13-2010
The make tool is designed for this. When you run 'make', it reads Makefile from the current directory to see if it needs to build anything.

Here's a simple Makefile that creates output from file1, file2, file3, file4:
Code:
output:file1 file2 file3 file4
        cat file1 file2 file3 file4 > $@

Note that the eight spaces in front of the cat command are actually one tab and must be a tab for make to understand the file.

The first line tells it to make output from the files listed after :. I think wildcards are allowed, so you could put that as file* instead of file1 file2 file3 file4. When you run make, it will check if any of the input files are newer than output and re-create it if necessary. If none of those files are newer than output, it will do nothing.

You can specify as many rules as you want, in any order, but the first rule is the one it actually attempts to build, so, you'd usually have an empty rule like:

Code:
all:output1 output2 output3 output4

at the top, which will cause make to check the rules to build output1, output2, output3, output4, etc.

Last edited by Corona688; 04-13-2010 at 06:21 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compiling and Executing a Java File With a Shell Script

I'm trying to use a shell script to compile and execute a java file. The java classes are using sockets, so there is a client.java file and a server.java file, each with their own shell script. I also want to handle the command line arguments within the shell script, not the java classes. The... (1 Reply)
Discussion started by: britty4
1 Replies

2. OS X (Apple)

Compiling fails due to space in path to home folder

I seem to have issues compiling software and I think I've narrowed it down to something having to do with having a space in the path name to my Home folder (which contains "Macintosh HD"). The reason I think this is shown here: $ echo $HOME /Volumes/Macintosh HD/Users/Tom $ cd $HOME -sh:... (7 Replies)
Discussion started by: tdgrant1
7 Replies

3. UNIX and Linux Applications

Move Files From One Folder To Another In UNIX

There are around 13 files in folder1.I need to move these files to another folder folder2,one file at a time, after checking whether a file exists in another folder folder3. If a file exists in folder3, we should not move files from folder1 to folder2. If there are no files in folder3, we need... (1 Reply)
Discussion started by: Jassz
1 Replies

4. Shell Programming and Scripting

Last modified time of the folder is changing when I view the file inside the directory

Hi., Last modified time of the folder is changing when I view the file inside the directory. Here is the test on sample directory. I believe that ls -l commands gives the time detail w.r.t last modified time. Pl. suggest. bash-3.2$ mkdir test bash-3.2$ cd test bash-3.2$ touch myfile.txt... (2 Replies)
Discussion started by: IND123
2 Replies

5. Programming

Java Compiling Help**URgent**

I am compling simple java program HelloWorld.java although /usr/bin @ this path javac is present, is there any command line wherein i can pass the this option as well lik javac -opttion(javac path) filename.java as i do not have permissions to set path. Also wht does this error, means...... (0 Replies)
Discussion started by: niceboykunal123
0 Replies

6. Shell Programming and Scripting

Shell script to find out 2 last modified files in a folder..PLZ HELP!!!!!!!!!

hi all, I need to find out the last 2 modified files in a folder.There is some way by which,we can check the timestamp and find out..??please help this is urgent. Thanks in Advance Anju (3 Replies)
Discussion started by: anju
3 Replies

7. UNIX for Dummies Questions & Answers

Java compiling error

I need Help folks; I'm very new to Java & i was trying to compile some java files & i got a lot of errors (see below), could some one tell me what am i doing wrong? These are the files i need to compile: AddCommentActionLogging.java EditPageActionLogging.java When i run:... (4 Replies)
Discussion started by: Katkota
4 Replies

8. Programming

unix C++: get the files from a folder

Hello everybody! How can I get the list of files from a folder in C++ (unix)? thanks in advance for any help! regards (2 Replies)
Discussion started by: nadiamihu
2 Replies

9. UNIX for Dummies Questions & Answers

Viewing files of another unix server (in a folder)

I think that's what I'm trying to do. This is the problem: I log onto my comp, Comp1. Then, from the terminal, since my web server is on another comp, I type: xrlogin Comp2, so I log on to that computer. I then navigate to my directory by typing: cd /domain/myDir, so I am in my directory, on the... (3 Replies)
Discussion started by: Djaunl
3 Replies

10. Solaris

question about JAVA compiling ..

Hi , I don't know if this is the right place to post my question because it relates to JAVA . I am beginner of JAVA , using a tutorial as reference I am trying to run a simple program in JAVA env. I have installed JDSK kit from java.sun.com but when I tried to run a program from the DOS prompt , I... (7 Replies)
Discussion started by: ANAMIKA56
7 Replies
Login or Register to Ask a Question