简体   繁体   中英

Building Java package (javac to all files)

如何将目录中的所有文件编译为* .class文件?

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)?

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 .

Here's a code fragment that I use to build an entire project where, as usual, source files are in a deeply nested hierarchy and there are many .jar files that must go into the classpath (requires UNIX utilities):

CLASSPATH=
for x in $(find | grep jar$); do CLASSPATH="$CLASSPATH:$x"; done
SRC=$(find | grep java$)
javac -cp "$CLASSPATH" $SRC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM