简体   繁体   English

如何从命令行运行增量编译的NetBeans应用程序?

[英]How do I run an incrementally-compiled NetBeans application from the command line?

I tend to develop a lot of console applications using NetBeans. 我倾向于使用NetBeans开发许多控制台应用程序。 Many of these applications use arguments from the command line, which I constantly change while testing and debugging, so it is frustrating to have to pull up a dialog box in NB every time I want to change the arguments. 这些应用程序中的许多应用程序都使用命令行中的参数,我在测试和调试时会不断对其进行更改,因此每次要更改参数时都必须在NB中弹出一个对话框,这令人沮丧。 Furthermore, many of these arguments are filenames, which I like having tab-completion for, which isn't available in the dialog box. 此外,这些参数中的许多都是文件名,我喜欢使用制表符补全功能,而该名称在对话框中不可用。

What I resort to now is compiling a jar every time and running the application in a separate terminal window, because there I can run the application many times quickly while altering the command line arguments, and using tab completion to my heart's content. 我现在要使用的方法是每次编译一个jar并在单独的终端窗口中运行该应用程序,因为在那里我可以快速运行该应用程序很多次,同时可以更改命令行参数,并使用制表符完成我的内心。 However, this scheme is painful as I can no longer use incremental compilation, as the incrementally-compiled files do not show up in the classpath. 但是,由于无法再使用增量编译,因此该方案很痛苦,因为增量编译的文件不会显示在类路径中。 So I'm forced to make a jar every time, which is slow. 所以我每次都被迫做一个罐子,这很慢。

My question is how can I have the best of both worlds? 我的问题是我怎样才能两全其美? I want to be able to be able to run my app quickly after making quick changes in the code (incremental compilation) but alter command line args quickly as well. 我希望能够在代码中进行快速更改(增量编译)后迅速运行我的应用程序,但也能快速更改命令行参数。

What I thought about was trying to change my classpath so it includes the location where the incrementally-compiled files go, but after reading the NB docs on incremental compilation, I'm not sure that would be enough. 我想到的是尝试更改类路径,使其包含增量编译文件所在的位置,但是在阅读了有关增量编译的NB文档后,我不确定是否足够。

The incremental compiler leaves classes in the directory build/classes . 增量编译器将类保留在目录build/classes Given this example: 给出以下示例:

package cli;
import java.util.Arrays;
public class Hello {
    public static void main(String[] args) {
        String s = "Hello, world! -> ";
        System.out.println(s + Arrays.toString(args));
    }
}

I get these command line results after saving any source code changes, ie without explicitly recompiling: 保存任何源代码更改后,即没有显式重新编译,我将获得以下命令行结果:

$ java -cp build/classes cli.Hello
Hello, world! -> []
$ java -cp build/classes cli.Hello 123
Hello, world! -> [123]
$ java -cp build/classes cli.Hello 123 456
Hello, world! -> [123, 456]

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

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