Mastering NetBeans
上QQ阅读APP看书,第一时间看更新

Building NetBeans

Once we've downloaded the source code for NetBeans, we can build it either using the command line or via NetBeans.

To build the NetBeans IDE from the source code, we need to have the following software installed first:

  • JDK 7
  • Apache Ant

Tip

NetBeans can be built with JDK 8, but additional steps are required for this; we'll see what these are shortly!

Building NetBeans via the command line

To build NetBeans via the command line, open up a terminal or command prompt and change the directory to the directory containing the source code. Executing the ant command will build the source code, downloading any external dependencies that are required:

[david:~/Develop/NetBeans/main-silver]$ ant

If you are running JDK 8 instead of 7, you will be presented with an error when attempting to build the source code stating that builds are forbidden when using JDK 8. This error is presented so as not to introduce any Java 8 features into the source code.

Building NetBeans via the command line

If you wish to use JDK 8 to build the code, you can set the permit.jdk8.builds property to true:

[david:~/Develop/NetBeans/main-silver]$ ant –Dpermit.jdk8.builds=true

Alternatively, if you have both JDK 7 and 8 installed, you can set the nbjdk.home property to point to a valid JDK 7 installation and the build will then complete using the specified JDK 7 instead of JDK 8.

Once you have successfully build NetBeans, you can execute the freshly built instance by executing the ant tryme task:

[david:~/Develop/NetBeans/main-silver]$ ant tryme

This will execute the instance of NetBeans that you have just built using <build-location>/nbbuild/testuserdir as the user directory. The actual instance of NetBeans is stored within the <build-location>/nbbuild/netbeans folder.

Building NetBeans via the command line

Alternatively, you can also start the freshly-built instance of NetBeans by executing the netbeans or netbeans.exe commands from within the <build-location>/nbbuild/netbeans/bin directory, either from the command line of Windows / Linux explorer or Mac OSX Finder.

Building NetBeans from within NetBeans

Now that we've seen how to build NetBeans via the command line, let's see how we can build it from within NetBeans itself.

If you cloned the NetBeans source code via the team support in NetBeans, then the NetBeans Build System project will already be opened within NetBeans, ready for building, as shown in the following screenshot:

Building NetBeans from within NetBeans

If you cloned NetBeans via the command line, you will need to open the NetBeans Build System project located within the main-silver/nbbuild directory.

Building NetBeans from within NetBeans

After opening the project, you will see that there are error badges shown against the Ant Tasks and Tests for Ant Tasks project nodes within the Projects window. These errors simply indicate that artifacts needed for the build haven't been downloaded yet; the build process will download the necessary files, and once built, these error badges will no longer appear.

To start building NetBeans, we must first build the necessary Ant tasks that the full build process relies on. To perform this, right-click on the NetBeans Build System project and select the Build option:

Building NetBeans from within NetBeans

Once the build system is completed with no errors (you will see several warnings displayed during the build process, but these can be safely ignored), you can build NetBeans by right-clicking on the NetBeans Build System project and selecting the Build IDE (No ZIP File) option:

Building NetBeans from within NetBeans

If you are using JDK 7, you will see that NetBeans is built correctly after a few minutes of activity.

If you are using JDK 8, you will see a failure message in the NetBeans output window, indicating that the project cannot be built using JDK 8, as shown in the following screenshot:

Building NetBeans from within NetBeans

Since NetBeans provides its own installation of Ant to build projects, if we wish to use JDK 8 to build NetBeans, we must configure the permit.jdk8.builds property before attempting to build.

To configure the Ant properties from within NetBeans, perform the following steps:

  1. Open the NetBeans Options dialog. On Windows and Linux, this is achieved by selecting Tools and then Options from the main menu. On Mac OS X, clicking on NetBeans and then Preferences from the application menu opens the Options dialog.
  2. In the Options dialog, click on the Java option and then choose the Ant tab.
  3. Within the Ant tab, append the permit.jdk8.builds=true line into the Properties edit box:
    Building NetBeans from within NetBeans
  4. Click on the OK button to save the configuration changes.

Now that we've configured the permit.jdk8.builds property for the internal instance of Ant, we can build the project successfully using JDK 8. This is achieved by right-clicking on the NetBeans Build System project within the Projects window and selecting the Build IDE (No ZIP File) option.