如何在 Eclipse 中编译 Java 程序而不运行它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4058155/
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
How can I compile a Java program in Eclipse without running it?
提问by Jonas
I would like to compile my Java program in Eclipse but not to run it. I can't understand how to do it.
我想在 Eclipse 中编译我的 Java 程序,但不想运行它。我不明白该怎么做。
How can I compile a Java program to .class
files in Eclipse without running it?
如何将 Java 程序编译为.class
Eclipse 中的文件而不运行它?
采纳答案by Cristina
You can un-check the build automatically in Project menu and then build by hand by type Ctrl + B, or clicking an icon the appears to the right of the printer icon.
您可以在项目菜单中自动取消选中构建,然后通过键入 Ctrl + B 手动构建,或单击出现在打印机图标右侧的图标。
回答by Charidimos
You will need to go to Project->Clean...,then build your project. This will work, even when your source code does not contain any main method to run as an executable program. The .class files will appear in the bin folder of your project, in your workspace.
您需要转到Project->Clean...,然后构建您的项目。即使您的源代码不包含任何作为可执行程序运行的 main 方法,这也将起作用。.class 文件将出现在您项目的 bin 文件夹中,在您的工作区中。
回答by Clint Willard
In the case that you delete your .class file in Eclipse and then try to build it again from the .java file it will do nothing. If you try to run the .java file without the .class file you will get an error that it can not find the main class.
如果您在 Eclipse 中删除 .class 文件,然后尝试从 .java 文件再次构建它,它将什么也不做。如果您尝试在没有 .class 文件的情况下运行 .java 文件,您将收到一个错误,指出它找不到主类。
You will either have to change and re-save the .java file then build it again, or else you have to run Clean on the project then build again.
您要么必须更改并重新保存 .java 文件,然后再次构建它,要么您必须在项目上运行 Clean 然后再次构建。
回答by Dipanshu
Go to the project explorer block ... right click on project name select "Build Path"-----------> "Configuration Build Path"
转到项目资源管理器块...右键单击项目名称选择“构建路径”----------->“配置构建路径”
then the pop up window will get open.
然后弹出窗口将打开。
in this pop up window you will find 4 tabs. 1)source 2) project 3)Library 4)order and export
在此弹出窗口中,您将找到 4 个选项卡。1) 源 2) 项目 3) 库 4) 订购和导出
Click on 1) Source
点击 1) 来源
select the project (under which that file is present which you want to compile)
选择项目(在该项目下存在要编译的文件)
and then click on ok....
然后点击确定....
Go to the workspace location of the project open a bin folder and search that class file ...
转到项目的工作区位置打开一个 bin 文件夹并搜索该类文件...
you will get that java file compiled...
你会得到那个java文件编译...
just to cross verify check the changed timing.
只是为了交叉验证检查更改的时间。
hope this will help.
希望这会有所帮助。
Thanks.
谢谢。
回答by Leeladurga Prasad Gunti
Right click on Yourproject(in project Explorer)-->Build Project
右键单击 Yourproject(in project Explorer)-->Build Project
It will compile all files in your project and updates your build folder, all without running.
它将编译您项目中的所有文件并更新您的构建文件夹,所有这些都无需运行。
回答by Jorge Nieto
Try this in your console:
在你的控制台中试试这个:
javac {$PathToYourProyect}/*
If you also need any external library, try:
如果您还需要任何外部库,请尝试:
javac -cp {$PathToYourLibrary}.jar {$PathToYourProyect}/*
回答by Sanjay Singh Bhandari
Right click on the file on package Explorer Then go to Show in Under it go to terminal Eclipse will have a terminal then Use javac fileName to compile
右键单击包资源管理器上的文件然后转到 Show in 在它下转到终端 Eclipse 将有一个终端然后使用 javac fileName 进行编译