Building Java package (javac to all files)

旧街凉风 提交于 2019-12-03 05:36:51

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!