Working with NIO2 - Part I - Building OpenJDK7 With NIO2
By deniz. Thursday, September 25, 2008 11:22:34 AM
My name is Deniz, and I work in Opera QA, Systems and Processes on tools development. We mainly create tools for automation, stress testing, and various other stuff. In this first post, I will try to guide you on building the OpenJDK platform, in upcoming posts I will give samples on how to use it.
Here at QA SaP, we try to keep up with the latest technologies, and Java is no exception. After the announcement of NIO2, I had my eyes on ea(early access) builds to test the new APIs to see if it would solve my long-lasting issues with NIO.
So, what is NIO2 and why is it useful? NIO APIs in Java, compared to old regular IO, provides features for intensive I/O operations. For example, we have used NIO with our proprietary stress tester tool—which would not be possible to implement in standard IO, and it proved to be very useful. However, we had some problems with it in terms of scalability and maintenance and those were targeted by Sun in NIO2. Moreover, they introduced a bunch of new File IO APIs—such as New File System API, useful for creating a wide range of tools with ease.
Finally, Sun released the implementation—first with a patch; later it was merged to repository (mercury/hg), but they had no binary builds available.
So, I wanted to compile the source code —after they released it as a patch. However, it wasn't as easy at it may sound hence the reason for this tutorial. Luckily, Sun started providing the binaries for all platforms some time ago, but we think it is a good idea to be on the bleeding edge and to be able to build the jdk7 on your own.
I would like to mention that this tutorial is based on Rajendra's post—which really helped me a lot during the build—and Elliotte's post on java.net. I thought it would be helpful to have everything in one place, providing links to downloads, listing packages, and so forth. I tried to combine both posts, clean the obsolete packages, and provide links to files, which should speed up the process for you.
The building platform is Ubuntu 8.04 i586/x64 (I am on x64), which is up to date as of writing this post. I tried to put all Java-related files to /opt/java; by just changing the directories (/opt/java and /home/operaqa), you should have no problems compiling.
- First, we need the following packages:
- The jdk repository needs the forest extension for mercurial; since we have mercurial now, we simply need to get the extension: If you are on a proxied connection, first set it as follows: > export http_poxy=your proxy > hg clone http://hg.akoha.org/hgforest Next, set the forest configuration variable to the path of forest.py in extensions section of ~/.hgrc file to enable forest extension: forest=/home/operaqa/hgforest/forest.py
- Now, we can fclone the jdk7 nio2 mercurial repository: > hg fclone http://hg.openjdk.java.net/nio/nio jdk7
- Download the binary plugs JAR and run it to create the openjdk-binary-plugs directory.
- Then, download findbugs and extract it.
- Note that gcc will fail on default Ubuntu installation. To fix this failure, go to jdk7/hotspot/make/linux/makefiles and execute the following command to edit the makefile: > echo "CFLAGS += -Wno-write-strings" >> gcc.make
- You also need to switch to bash or to delete the /bin/sh and create a symbolic link as follows: > sudo rm sh > sudo ln -s bash sh
- Next, set the following environment variables: > export ALT_BOOTDIR=/usr/lib/jvm/java-6-sun-1.6.0.06 - where JDK 6 is installed > export ALT_BINARY_PLUGS_PATH=/opt/java/openjdk-binary-plugs - wherever binary plugs is installed > export FINDBUGS_HOME=/opt/java/findbugs-1.3.4 - wherever findBugs is installed > export LANG=C
- Then, make jdk7/jdk/make/jdk_generic_profile.sh executable and run it: > chmod +x jdk_generic_profile.sh > ./jdk_generic_profile.sh
- Go to the root folder of jdk7 and enter the following command: > make sanity
- If the sanity check passes (it should), enter as follows: > make Note: This is likely going to take some time, depending on your machine—a good excuse to go grab a cup of coffee.
- The resulting binaries will be in build directory build/linux-amd64. You can now copy j2sdk-image to /opt/java/jdk7 and start using it.