简体   繁体   English

构建Java包(javac到所有文件)

[英]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. 到javac为输出创建正确的目录结构。

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: 在此处描述了在UNIX上使用“find”的另一种方法:

http://stas-blogspot.blogspot.com/2010/01/compile-recursively-with-javac.html 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: 以下两个命令将编译目录./src及其子目录中包含的所有.java文件:

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. 首先, find生成sources_list.txt ,这是一个包含Java源文件路径的文件。 Next, javac compiles all these sources using the syntax @sources_list.txt . 接下来, javac使用语法@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): 这是我用来构建整个项目的代码片段,像往常一样,源文件位于深层嵌套的层次结构中,并且有许多.jar文件必须进入类路径(需要UNIX实用程序):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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