Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building Java package (javac to all files)

Tags:

java

javac

How to compile all files in directory to *.class files?

like image 615
Vytas P. Avatar asked Mar 01 '10 14:03

Vytas P.


People also ask

What is the command to compile all Java files in the current directory?

Description. The javac command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the Java Virtual Machine. The javac command can also process annotations in Java source files and classes.


2 Answers

Well, this seems pretty obvious, so I may be missing something

javac *.java

(With appropriate library references etc.)

Or perhaps:

javac -d bin *.java

to javac create the right directory structure for the output.

Were you looking for something more sophisticated? If so, could you give more details (and also which platform you're on)?

like image 190
Jon Skeet Avatar answered Sep 16 '22 14:09

Jon Skeet


Yet another way using "find" on UNIX is described here:

http://stas-blogspot.blogspot.com/2010/01/compile-recursively-with-javac.html

The following two commands will compile all .java files contained within the directory ./src and its subdirectories:

find ./src -name *.java > sources_list.txt
javac -classpath "${CLASSPATH}" @sources_list.txt

First, find generates sources_list.txt, a file that contains the paths to the Java source files. Next, javac compiles all these sources using the syntax @sources_list.txt.

like image 33
Kipton Barros Avatar answered Sep 18 '22 14:09

Kipton Barros