简体   繁体   English

如何在Netbeans中编译单个Java文件?

[英]How to compile single Java file in Netbeans?

I have following code in project called Fork. 我在名为Fork的项目中有以下代码。

package fork;

public class Fork {

    public static void main(String[] args) {

       if (args.length == 1 | args[1].equals("test")) {
           System.out.println("test case");
       } else {
           System.out.println("production " + args[0]);
       }      

    }

} 

Project Structure in Netbeans is as follows: Netbeans中的项目结构如下:

NetBeans中的项目结构

I am trying to make changes in the Fork.java. 我试图在Fork.java中进行更改。 It would not build successfully because args[ 1 ] gives an error on runtime, which is alright. 它不会成功构建,因为args [1]在运行时给出了一个错误,可以。 So, What I do is compile the Fork.java using "javac Fork.java" command in Terminal outside Netbeans. 因此,我要做的是在Netbeans外部的Terminal中使用“ javac Fork.java”命令来编译Fork.java。 Then the changes reflect in the output. 然后,更改将反映在输出中。

For instance, I would run the following command from Terminal in my Mac or from the Terminal within Netbeans (both respond same way): "java Fork live test" 例如,我将在Mac的Terminal或Netbeans的Terminal中运行以下命令(两种方式均响应):“ java Fork live test”

Then I would make some changes in Fork.java and Save it. 然后,我将在Fork.java中进行一些更改并保存。 I have "Compile on save" enabled in my project properties. 我在项目属性中启用了“保存时编译”。

I would run again the above command, but the changes would not reflect in the output. 我将再次运行上面的命令,但是更改不会反映在输出中。 To see the changes, I would have to go to the Folder where Fork.java is saved, and then compile it using "javac Fork.java" in Terminal. 要查看更改,我必须转到保存Fork.java的文件夹,然后在终端中使用“ javac Fork.java”对其进行编译。 Then I would run the "java Fork live test" from Terminal and see the changes. 然后,我将在Terminal中运行“ java Fork实时测试”并查看更改。

I am interested to see whether Netbeans has any equivalent way to compile a single file. 我很想知道Netbeans是否具有任何等效的方式来编译单个文件。

I'm guessing you want to run Fork with arguments (live test) using the NetBeans IDE. 我猜想您想使用NetBeans IDE使用参数(实时测试)运行Fork。 You don't want to go through the command line. 您不想通过命令行。

  1. Right Click on Cup and Saucer icon -> Properties 右键单击杯子和碟子图标->属性
  2. Go to Run, add live test in the Arguments box 转到运行,在“参数”框中添加实时测试
  3. Run Project F6. 运行项目F6。

You code builds successfully using Clean and Build Project Shift+F11 您使用Clean and Build Project Shift + F11成功编译了代码

F9在编辑器窗口中编译当前文件

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

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