我可以使用 JAVAC 编译具有多个文件和目录的项目吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/864630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I use JAVAC to compile a project with multiple files and directories?
提问by Monster
I'm working on a very large project that has associated class files in multiple directories, all stemming from the root dir \src.
我正在处理一个非常大的项目,该项目在多个目录中关联了类文件,所有这些文件都源自根目录 \src。
I'm trying to compile a file in src\solution\ (called Console.java) that uses imports from other directories in the src, which are still uncompiled.
我正在尝试在 src\solution\(称为 Console.java)中编译一个文件,该文件使用来自 src 中其他目录的导入,这些目录仍未编译。
So if I want to compile Console.java outside of an IDE, how do I go about doing that? Oh yeah, I also have some external JARs which need to be included in the build.
因此,如果我想在 IDE 之外编译 Console.java,我该怎么做呢?哦,是的,我还有一些需要包含在构建中的外部 JAR。
Thanks! I appreciate it!
谢谢!我很感激!
采纳答案by mtpettyp
回答by shsteimer
I'm a little unclear on your specific requirements, but what your asking is almost certainly possible. You might want to take a look at the javac options, and see what you can find that will help you.
我对您的具体要求有点不清楚,但是您的要求几乎肯定是可能的。您可能想查看 javac 选项,看看您能找到哪些对您有帮助的内容。
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html#options
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html#options
For example, for the external .jars you need, those need to be included in your classpath using the -classpath option.
例如,对于您需要的外部 .jar,需要使用 -classpath 选项将它们包含在您的类路径中。
回答by NamshubWriter
You definitely want a build tool. You might want to look at these questions:
你肯定想要一个构建工具。你可能想看看这些问题:
回答by Andreas Dolk
javac comes with two options, that might help you her:
javac 有两个选项,可能对你有帮助:
-c path/to/one/jar;path/to/another/jar对于图书馆和
-s path/to/src/solution/java;path/to/src/test/java对于源文件。这值得一试。