Setup Oracle JDK 7 + Netbeans 7.0.1 on Ubuntu 12.04 LTS

In this post we will see how to setup a basic environment to develop Java applications on a Ubuntu Precise Pangolin. Normally this setup should be a very simple operation, anyway I had some trouble during process, so I decided to write down and describe all steps I followed to sort out.

First of all, I installed Oracle Java Development Kit using specific webupd8team repository.

Please note that this step is mandatory because using ubuntu openjdk package, Netbeans won’t be able to work correctly: in fact new project window will lock down on “please wait…” message.

So let’s open a terminal and run following commands:

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java7-installer oracle-java7-set-default

When process is finished, we should check if oracle java is correct installed and used as system Java Virtual Machine. To do that we can simply run following command and check resutlt:

$ java -version

If everything is ok, the result is something like this:

java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

If for any reason, the result differs from above, try to run:

$ sudo update-java-alternatives -s java-7-oracle

and then run java version check again.

Now we can install Netbeans by running following command:

$ sudo apt-get install netbeans

We are almost done. Now Netbeans runs, but it’s design mode can’t work properly: it simply remains on loading message. To fix this issue, we will install libbatik library and will run Netbeans with a non-standard opition.

Run following command to install needed library:

$ sudo apt-get install netbeans libbatik-java

Now, we can try Netbeans work correctly by running:

$ /usr/bin/netbeans -cp:a /usr/share/java/batik-ext.jar

Everything should be ok… but we are lazy and we won’t open a terminal everytime we need to use Netbeans, so let’s fix default launcher!

To edit Netbeans desktop entry, run:

$ sudo nano /usr/share/applications/netbeans.desktop

File content should be something like this:

[Desktop Entry]
Name=NetBeans IDE 7.0.1
Comment=Integrated Development Environment
TryExec=/usr/bin/netbeans
Exec=/usr/bin/netbeans
Icon=/usr/share/netbeans/7.0.1/nb/netbeans.png
Categories=Development;IDE;Java;
Terminal=false
Type=Application
StartupNotify=true

We simply have to replace Exec actual value (line 5) with /usr/bin/netbeans -cp:a /usr/share/java/batik-ext.jar. So it should appear like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[Desktop Entry]
Name=NetBeans IDE 7.0.1
Comment=Integrated Development Environment
TryExec=/usr/bin/netbeans
Exec=/usr/bin/netbeans -cp:a /usr/share/java/batik-ext.jar
Icon=/usr/share/netbeans/7.0.1/nb/netbeans.png
Categories=Development;IDE;Java;
Terminal=false
Type=Application
StartupNotify=true

Save and quit.

At this point we are ready to launch Netbeans and start to develop!