问题
I would like to compile the project every time I save, but in properties this option is greyed, so for any change I do I have to click save then clean and build.
How can I do to avoid to clean and build for every code modification?
回答1:
Change your netbeans project's project.properties like below.
Find below line in project.properties file
compile.on.save.unsupported.javafx=true
Change this value to set to false
compile.on.save.unsupported.javafx=false
After change this file, compile on save option will be enabled and you are good to go.
回答2:
Answer for Apache NetBeans 9, 10, 11 using Maven.
Configuration is set at nbactions.xml file, usually it'll look similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>war</packaging>
<packaging>ear</packaging>
<packaging>ejb</packaging>
</packagings>
<goals>
<goal>package</goal>
</goals>
</action>
</actions>
To activate the Compile On Save option you only need to add the <netbeans.compile.on.save> setted to all, it'll look like this:
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>war</packaging>
<packaging>ear</packaging>
<packaging>ejb</packaging>
</packagings>
<goals>
<goal>package</goal>
</goals>
<properties>
<netbeans.compile.on.save>all</netbeans.compile.on.save>
</properties>
</action>
</actions>
Also...
At latest NB 10 and 11 you may see the warning It is recommended to install nb-javac Library to improve Java editing experience and enable compile on save at Notifications section:
You just need to install that plug-in (nb-javac) by clicking on that link, more info here, there's currently an open issue for NB11.2, if you have problems with it try using beta 3 (or latest)
回答3:
You should choose the Sources rather than Build from the Categories.
来源:https://stackoverflow.com/questions/17103371/how-to-compile-on-save