简体   繁体   中英

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

I tend to develop a lot of console applications using 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. 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. 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.

The incremental compiler leaves classes in the directory 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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