Wednesday, October 9, 2013

JDK 8 under Ubuntu - Part 1

Ok, here's what seems work to set up JDK 8 and NetBeans under linux (ubuntu).

1. Install JDK 7 (there are problems running NetBeans under JDK 8, so we need to have 7 as the default JDK) - sudo apt-get install openjdk-7-jdk After that it appears under /usr/lib/jvm (we'll need to know where it is, really!).

2. Download NetBeans 7.4 from this address http://bertram2.netbeans.org:8080/job/jdk8lambda/1691/artifact/nbbuild/NetBeans-jdk8lambda-basic.zip. Extract the netbeans folder it somewhere (I put it into my home directory)

3. Read through the documentation - it's stand-alone and needs to be started over a terminal, like for me it then start as ~/netbeans/bin/netbeans. Start it, see if it works, close it.

4. Install the Oracle JDK 8 - I found this a little easier than installing the current JDK 8 OpenJDK preview:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer


Thanks to http://www.liberiangeek.net/2012/09/install-oracle-java-8-jdk-jre-in-ubuntu-12-04/ for that!

You will find the JDK also under /usr/lib/jvm as java-8-oracle.

5. Use javac -version and java -version to see what version is the current default - it's something like 1.8.0-ea and not what you want!

6. Use sudo update-alternatives --config java and
sudo update-alternatives --config javac to change the defaults for VM and compiler to JDK 7. Convince yourself that it worked (see 5).

7. Start NetBeans up again, create a new Java project.

8. Under Tools --> Java Platforms add JDK 8 by Add Platform, navigating to /usr/lib/jvm and selecting the java-8-oracle folder.

9. Open the Properties of your Java project, select JDK 1.8 under Libraries/Java Platform. Under Sources select JDK 8 as Source/Binary Format.

10. The next step might save you some frustration: Still under Properties/Build/Compiling deselect Compile on Save. At least today that's just not working! You have to manually compile! Ok the Properties dialog.

11. Create a class RunnableTest:

public class RunnableTest {

    public static void main(String[] args) {

        Runnable r = () -> {
            System.out.println("Hello world!");
        };
        r.run();
    }
}


Compile with F9 (or the context menu, of course) - then run it!

Good luck!


No comments:

Post a Comment