Alberto acepsut
Alberto acepsut

Reputation: 2022

How to compile on save?

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.

enter image description here

How can I do to avoid to clean and build for every code modification?

Upvotes: 3

Views: 14759

Answers (3)

luiscla27
luiscla27

Reputation: 6469

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:

enter image description here

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)

Upvotes: 3

DeepInJava
DeepInJava

Reputation: 1961

Change your netbeans project's project.properties like below.

  1. Find below line in project.properties file

    compile.on.save.unsupported.javafx=true

  2. Change this value to set to false

    compile.on.save.unsupported.javafx=false

  3. After change this file, compile on save option will be enabled and you are good to go.

Upvotes: 3

Abraham Guchi
Abraham Guchi

Reputation: 181

You should choose the Sources rather than Build from the Categories.

Upvotes: 1

Related Questions