如何在 LINUX shell 上用 Java 编译多个类文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22002963/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 11:58:09  来源:igfitidea点击:

How to compile multiple class files in Java on LINUX shell?

javalinuxclassshell

提问by user3349184

Hello I am on campus trying to compile a simple binary tree program .. our campus only has shell and I am using Linux over eclipse..

你好,我在校园里试图编译一个简单的二叉树程序..我们的校园只有 shell,我在 eclipse 上使用 Linux..

I have 2 class files in my current directory bintree.java and treetest.java

我在当前目录 bintree.java 和 treetest.java 中有 2 个类文件

javac bintree.java treetest.java

this code creates multiple classes but what is my next step? ive searched everywhere theres not a lot of info on java Linux shell. thank you

这段代码创建了多个类,但我的下一步是什么?我到处搜索,没有很多关于 java Linux shell 的信息。谢谢你

采纳答案by jeremyjjbrown

If all of the java files you need to compile are in your directory you can

如果您需要编译的所有 java 文件都在您的目录中,您可以

javac *.java 

And then

进而

java NameOfClassWithMainMethod

Otherwise if you want to learn to work without an IDE I would suggest learning to use Mavenor Gradle. They will abstract away a lot of the tedium of compiling a project, and if become a pro dev you'll need to know at least Maven anyway.

否则,如果您想学习在没有 IDE 的情况下工作,我建议您学习使用MavenGradle。它们将消除编译项目的许多单调乏味,如果成为专业开发人员,无论如何您至少需要了解 Maven。

回答by TheEwook

$ find -name "*.java" > sources.txt
$ javac @sources.txt

回答by ErstwhileIII

You might look at http://www.dummies.com/how-to/content/how-to-use-the-javac-command.html

你可以看看http://www.dummies.com/how-to/content/how-to-use-the-javac-command.html

When you run javac xxx.java xxy.java xxz.javayou should get several .class files as a result. Is your problem really with running the javac or getting the resultant classes to run your program?

当您运行时,javac xxx.java xxy.java xxz.java您应该会得到几个 .class 文件。您的问题真的与运行 javac 或获取结果类来运行您的程序有关吗?

If so you may want to look here at another stackoverflow questin

如果是这样,您可能想在这里查看另一个stackoverflow questin

Basically use java -cp classname for the class that has your "static Main()" in it

基本上将 java -cp classname 用于其中包含“静态 Main()”的类