4

How can I enable Compile on Save in Apache Netbeans IDE 11.0?

https://i.stack.imgur.com/OOYQE.png

Output of my java -version

java version "11.0.4" 2019-07-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.4+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.4+10-LTS, mixed mode)

I tried setting:

  • compile.on.save=true in nbproject/private/private.properties

  • compile.on.save=true in nbproject/private.properties

  • compile.on.save.unsupported.javafx=true in nbproject/private.properties

  • compile.on.save.unsupported.javafx=false in nbproject/private.properties

and possible combinations of these. But not to succeed so far.

sazzad
  • 5,740
  • 6
  • 25
  • 42
  • 1
    Does this answer your question? [How to compile on save?](https://stackoverflow.com/questions/17103371/how-to-compile-on-save) – luiscla27 Dec 09 '19 at 18:48
  • 1
    The title of the linked duplicate suggests that it is the same question as this one, but it is not. That other question, and its accepted answer, both specifically relate to JavaFX. The OP here is asking how to enable compile-on-save for any type of project, and specifically on NetBeans 11 which was released over six years after the linked question. Furthermore, the solutions for the two questions are completely different. Voting to reopen. – skomisa Dec 10 '19 at 00:38
  • 1
    @LuisLimas No it does not. If you read carefully, I've already tried the options described in the answers of that question which I also included in this question. – sazzad Dec 10 '19 at 06:23
  • In addition to the nb-javac plugin, keep in mind that your project has to be a maven one (pom.xml based). If your project is a gradle based one, forget about the Compile on save feature in Netbeans for your project :-( – Fonsito Oct 16 '20 at 22:01

2 Answers2

6

TLDR:

  • You need to install the nb-javac library to enable compile on save.
  • However, due to a NetBeans bug, you must use version 11.2 beta 3 of NetBeans for that to work.

You may be seeing this issue because you need to install the nb-javac library. To determine whether installation is necessary:

  • Open the Notifications window by selecting Window > IDE Tools > Notifications.
  • If installation is required there will be a message stating "Install nb-javac Library" in the Notifications window:

    nb-javac library

To install the nb-javac library:

  • Unfortunately you must use version 11.2 beta 3 (or later) of NetBeans. This is due to an unrelated problem with the installation of nb-javac.
  • You can download NetBeans 11.2 beta 3 from this page. The file is named netbeans-11.2-beta3-bin.zip. Just download the zip file, then unzip it in a new directory.
  • From version 11.2 beta 3 of NetBeans (or later), select the notification in the Notifications window.
  • Click the link in the right pane with the text "It is recommended to install nb-javac Library to improve Java editing experience and enable compile on save".
  • A wizard for installing the library will be shown:

    Wizard

  • Complete the steps in the wizard. Once installation is complete, restart NetBeans.

After restarting NetBeans you should find that:

  • The nb-javac library has been installed.
  • The Compile on Save checkbox for your project is enabled.

I could reproduce your problem in NetBeans 11.1, and I have verified that this solution worked for me.

Notes:

skomisa
  • 16,436
  • 7
  • 61
  • 102
1

The nbjavac plugin needs to be installed. See also here.

Joachim Rohde
  • 5,915
  • 2
  • 29
  • 46
  • 2
    While this is true, it's not the whole story since installing nb-javac will fail on NetBeans 11.0 or 11.1. – skomisa Oct 23 '19 at 09:25