How to build OpenJDK projects in Eclipse (for Ubuntu 12.04 LTS)

The instructions below specify how you can build the following OpenJDK projects using the Eclipse IDE for both the new InfraBuild and the Old Build systems:

Swing
JMX
JConsole
Langtools
JAXP and JAXWS
Hotspot
CORBA
JDK — sub-projects – Old Build
and
JDK — sub-projects – Infrabuild

Below is a list of systems and versions under which the installations and configurations were performed to come up with these instructions:

Synaptic Package Manager 0.75.9

Eclipse Indigo 3.7.2
—Eclipse JDT (Java) 3.7.2
—Eclipse CDT (C/C++)
——6.0.0.dist (C/C++ Remote debug launcher)
——1.0.2.dist (CDT GCC Cross Compiler)
——7.0.0.dist (GDB Common)

Ubuntu 12.04 LTS
Ant 1.8.2
OpenJDK 8
Java/Javac 1.7

In order to start, you have to create a VM (or install in your native environment), get the OpenJDK source code, install a number of packages, and build the OpenJDK from command line, as it described in Adopt OpenJDK VM Build (Old Build and InfraBuild).


Installing Eclipse for Java via the Synaptic Package Manager

Install Synaptic Package Manager using Ubuntu Software Centre

Install Eclipse packages via the Synaptic Package Manager by searching for “Eclipse-jdt” (without quotes).
Select eclipse-jdt from the packages list and the rest of the dependencies will also get selected.

eclipse-jdt

Eclipse Java Development Tool (eclipse-jdt)

Once that is done, click on Apply.
A Summary window will appear, click on the Apply button again.
Then wait till the Downloading Package Files is finished.
Run Eclipse via the Dash Home

DO NOT USE THE “Check for Updates” from the Help menu in Eclipse, this could lead to problems with the Java perspective or render the Eclipse platform unusable (error message). Although you can use the “Install New Software” option from the Help menu – its best not to.

PLEASE USE THE “Synaptic Package Manager” to do any “updates / upgrades” to Eclipse packages and plugins.

You can use the below commands (optional) to update and upgrade packages:

sudo apt-get update
(password requested)

sudo apt-get upgrade

Also accept any available updates from the Ubuntu Software Centre. Once this is done, a reboot of the Ubuntu system will be required.

Run Eclipse

Check if the Java perspective is available (see under File > New > New Project menu options).

JRE Runtime Environment
To add the run-time environment into Eclipse do the following:
a) Go to Windows > Preferences > Java
b) Select Installed JRE
c) Add a JRE by clicking on the Add button
d) Browse to the /usr/lib/jvm/java-7-openjdk-amd64 folder and select it.

Select Installed JRE

Select Installed JRE

e) Click on Finish to add the new JRE to Eclipse’s list of JREs.

InstalledJRE

InstalledJRE for all build.xml scripts

Shutdown Eclipse once done.


Installing Eclipse C/C++ plug-in (Eclipse CDT) via the Synaptic Package Manager

Run the Synaptic Package Manager
Search for “eclipse-cdt” (without quotes) and click on Search

eclipse-cdt

Eclipse C/C++ Development Tool (eclipse-cdt)

A list of packages appear, select ‘eclipse-cdt’ from the list. The a list of dependencies appear, select them all. Select Mark for Installation.
Click on the Apply button on the ribbon panel followed by a click on the Apply button at the bottom right hand corner.

If the Synaptic Package Manager detects updates/upgrades and wishes to perform them, accept and allow the changes to be applied.

Click on Next and finally Finished.

Post Eclipse installations, Eclipse would need to be restarted. Post installation of updates/upgrades Ubuntu would need to be restarted.

Before building any packages through command-line or Eclipse run the below command to install the ‘g++4.6-multlib’ library:

sudo apt-get install g++-4.6-multilib

It ensures that command-line and Eclipse build actions go smoothly wherever the g++ library is needed.

Preparing projects, folders and files

Go to into the ~/sources/jdk8_tl/jdk/make/ folder and copy the netbeans folder and call it eclipse. Similarly go into the ~/sources/jdk8_tl/langtools/make/ folder and copy the netbeans folder and call it eclipse.

Then go to the individual folders and rename the nbproject to ecproject wherever applicable. Remove the contents of this folder.

Open ~/sources/jdk8_tl/jdk/make/eclipse/common/shared.xml in a text editor, go to lines 130 and 132 and replace 1.5 and 1.6 to ${javac.version.source} and ${javac.version.target}. This will eventually be replaced in each of the individual build.properties files for each of the packages as shown below.

Iterate through the below folders to look for the build.xml and build.properties files, if either of them do not exist, create the file:

~/sources/jdk8_tl/jaxp/
~/sources/jdk8_tl/jaxws
~/sources/jdk8_tl/jdk/make/eclipse/j2se/
~/sources/jdk8_tl/jdk/make/eclipse/jconsole/
~/sources/jdk8_tl/jdk/make/eclipse/jmx/
~/sources/jdk8_tl/jdk/make/eclipse/swing/
~/sources/jdk8_tl/langtools/make/eclipse/langtools/

Ensure the build.xml scripts have Ant tasks in each of them.

Otherwise create them taking the build script at ~/sources/jdk8_tl/jdk/make/eclipse/swing/build.xml as an example. For one of the packages the Ant Task does exist but it is surrounded by comments, and would require uncommenting.

Look for the ‘javac’ tag in this file, a typical Ant task looks like the below:

    <target name="run" depends="-init">
        <property name="jvm.args" value=""/>
        <javac srcdir="${swing.demo.src}" destdir="${swing.demo.classes}"
            fork="true" failonerror="true"
            classpath="${dist.dir}/lib/swing.jar:${classes.dir}"
            debug="${javac.debug}" debuglevel="${javac.debuglevel}">
            <compilerarg line="${javac.options}"/>
        </javac>
        <java classname="SampleTree" classpath="${swing.demo.classes}"
            fork="true" failonerror="true"
            jvm="${bootstrap.jdk}/bin/java">
            <jvmarg line="${demo.bootclasspath}"/>
            <arg line="${jvm.args}"/>
        </java>
    </target>

Search and replace all references to the texts “netbeans” and “nbproject” in the above files, to “eclipse” and “ecproject” respectively (without the quotes).

Amend the build.xml scripts to include source files, output and distribution folders (optional).

Also insert the following line at the top of the build.xml file just under the tag for all the above build.xml files:

  <property name="build.properties" location="./build.properties"/>

After importing the above packages, change the JRE version of the build.xml for each of the packages from 1.6 to 1.7 by using the right-mouse-click,

Ant-EditConfiguration (1.6 to 1.7)

Change JRE from 1.6 to 1.7 for all build scripts.

select the menu option Run As > Ant Build…, select the JRE tab, select java-7-openjdk-amd64 from the list next to Separate JRE.

Ant-SelectingAntBuild

Starting the build process by running the Ant Build script.

From within all the build.xml files remove references to the -demo-init, shared-clean, etc… defined with the depends attribute in the tags. Alternatively create dummy ones in each of the script where required in order to validate them sucessfully.

Amend the Ant Task attached to the build.xml by opening the Ant properties page and checking the ‘clean’ task and reording the build and clean taks in the following order, by using the Order button:

clean or shared-clean
build

Now individually import these projects into Eclipse (after ensuring both Java and C/C++ projects can be loaded into Eclipse) after making amendments to the build.properties file for the relevant projects.

NewProject (Import project from Ant Build script)

NewProject (Import project from Ant Build script)

NewJavaProject (next screen)

NewJavaProject (next screen)

SelectBuildXML

Select the build.xml file to import the project.

a) Swing
Before importing any project make the following amendments

Insert the below lines to the ~/sources/jdk8_tl/jdk/make/eclipse/swing/build.properties file:
Old_Build

#PATH to JDK8
bootstrap.jdk=/home/openjdk/sources/jdk8_tl/build/linux-amd64_backup/j2sdk-image
basedir=~/sources/jdk8_tl/jdk/make/eclipse/swing/
javac.version.source=1.5
javac.version.target=1.7

InfraBuild

#PATH to JDK8
bootstrap.jdk=/home/openjdk/sources/jdk8_tl/build/linux-x64-normal-server-release/images/j2sdk-image
basedir=~/sources/jdk8_tl/jdk/make/eclipse/swing/
javac.version.source=1.5
javac.version.target=1.7

If file already exists check if the contents have the above lines, if not add these lines to the bottom of the build.properties file.

Run Eclipse and do the below:

Import a project using the Import a project from existing Ant BuildFile option from New > Project > Other, click on Browse, go to the ~/sources/jdk8_tl/jdk/make/eclipse/swing folder and select build.xml.

Once the build file is loaded, select the ‘Link to buildfile in the file system’ option. The project gets loaded as expected and gets the name defined in the script.

Open the build.xml properties by selecting the file, and selecting the Run As > Build Ant… option from the menu. Set the Target to “shared-clean, build” by selecting shared-clean from the list of targets and changing the order using the Order button.

Run the Build of Swing project by selecting the build.xml file and right mouse click on the Run as > Ant build option.

Observe the messages in the Console tab in Eclipse and wait for sometime till the build is complete (depends on performance of your computer).

See How to build the Swing project for a more detailed approach.

b) JMX
Perform the same step as for Swing using the respective files in the ~/sources/jdk8_tl/jdk/make/eclipse/jmx/ folder. Also amend the build.properties file in the same manner.

Run the Build of JMX project by selecting the build.xml file and right mouse click on the Run as > Ant build option.

Observe the messages in the Console tab in Eclipse and wait for sometime till the build is complete (depends on performance of your computer).

See How to build the JMX project for a more detailed approach.

c) JConsole
Perform the same step as for Swing using the respective files in the ~/sources/jdk8_tl/jdk/make/eclipse/jconsole/ folder.

Amend the build.properties file a bit diferent, insert the below lines instead:

Old Build

#PATH to JDK8
bootstrap.jdk=/home/openjdk/sources/jdk8_tl/build/linux-amd64_backup/j2sdk-image
basedir=~/sources/jdk8_tl/jdk/make/eclipse/jconsole/
javac.version.source=1.7
javac.version.target=1.7

InfraBuild

#PATH to JDK8
bootstrap.jdk=/home/openjdk/sources/jdk8_tl/build/linux-x64-normal-server-release/images/j2sdk-image
basedir=~/sources/jdk8_tl/jdk/make/eclipse/jconsole/
javac.version.source=1.7
javac.version.target=1.7

Run the Build of JConsole project by selecting the build.xml file and right mouse click on the Run as > Ant build option.

Observe the messages in the Console tab in Eclipse and wait for sometime till the build is complete (depends on performance of your computer).

See How to build the JConsole project for a more detailed approach.

d) Langtools

Edit the build.properties for langtools located under ~/sources/jdk8_tl/langtools,and amend the following bits in the boot.java.home section:

boot.java.home = /usr/lib/jvm/java-7-openjdk-amd64
boot.javac.source = 7
boot.javac.target = 7

Copy the build.properties file from the ~/sources/jdk8_tl/langtools/make/ folder to the ~/sources/jdk8_tl/langtools/make/eclipse/langtools folder.

In addition for langtools, change the following two tags at the top of the file from

<project name="langtools-netbeans" default="build" basedir="../../..">
       <property name="langtools.properties" location="make/netbeans/langtools/nbproject/private/langtools.properties"/>

to

<project name="langtools-eclipse" default="build" basedir="../../..">
       <property name="langtools.properties" location="make/eclipse/langtools/ecproject/private/langtools.properties"/>

Ensure the build.properties in the /home/openjdk/sources/jdk8_tl/langtools/make/ folder has the below line in it otherwise add/update it:

boot.java.home = usr/lib/jvm/java-7-openjdk-amd64

Build the project via the right-mouse click Run As > Ant Build option and wait for it to finish.

See How to build the Langtools project for a more detailed approach.

e) JAXP and JAXWS

For both these packages, edit the build.properties for each of them located under ~/sources/jdk8_tl/, add the below line to it:

bootstrap.dir=/usr/lib/jvm/java-7-openjdk-amd64

Perform the same tasks as for the Swing package with these two packages and watch for it to build.

Build the project via the right-mouse click Run As > Ant Build option and wait for it to finish.

See How to build the JAXP and JAXWS projects for a more detailed approach.

f) Hotspot

Building Hotspot via the command-line interface (Old build)

Perform the below instructions to build Hotspot using the old build system (ensure environment variables are set – see the sub-heading Old Build. And the ~/.bashrc file source-ed before proceeding):

source ~/.bashrc

cd ~/sources/jdk8_tl/hotspot/make
make clean
make all
-or-
make clean all

(the first make just does a clean build, the next one does a full or incremental build, whilst the last one always does a clean full build)

A successful build will result in the following build messages that can be found in the log file (https://github.com/neomatrix369/BuildHelpers/blob/master/EclipseProjectsForOpenJDK/Logs/hotspot/hotspotBuild.log). An incremental (another attempt) build results in the following log messages (https://github.com/neomatrix369/BuildHelpers/blob/master/EclipseProjectsForOpenJDK/Logs/hotspot/hotspotBuild2ndPass.log).

Building Hotspot via the command-line interface (InfraBuild)

Configuration
We do not need to set the ALT_BOOTDIR or ALT_JDK_IMPORT_PATH environment variables, instead use the –with-jdk=/usr/lib/jvm/java-7-openjdk-amd64 parameter when calling the configure bashscript, for e.g.

bash ../autoconf/configure –with-boot-jdk=/usr/lib/jvm/java-7-openjdk-amd64/

run the above command from within the ~/sources/jdk8_tl/common/makefiles folder. The jdk or jre path specified with the –with-jdk parameter may vary and is specific to your linux environment.

A successful run results in the output of the following log messages (https://github.com/neomatrix369/BuildHelpers/blob/master/EclipseProjectsForOpenJDK/Logs/configureInfraBuild.log).

Building
Perform the below instructions to build Hotspot using the Infrabuild system (ensure the necessary enviroment variables are set and the ALT_… environment variables are unset – see the sub-heading InfraBuild. And the ~/.bashrc file source-ed before proceeding)

source ~/.bashrc
make clean hotspot NEW_BUILD=true &> hotspotInfraBuild.log

A successful run results in the output of the following log messages (https://github.com/neomatrix369/BuildHelpers/blob/master/EclipseProjectsForOpenJDK/Logs/hotspot/hotspotInfraBuild.log). An incremental (another attempt) build results in the following log messages (https://github.com/neomatrix369/BuildHelpers/blob/master/EclipseProjectsForOpenJDK/Logs/hotspot/hotspotInfraBuild2ndPass.log).

Perform the configuration settings in Eclipse for Hotspot using the instructions at Eclipse C/C++ (CDT) – Hacking Hotspot in Eclipse and the Adding include paths to your C/C++ project instructions sets.

Ensure the below environment variables are added to the project:
Old Build

LANG=C
ALT_BOOTDIR=/usr/lib/jvm/java-7-openjdk-amd64
ALT_JDK_IMPORT_PATH=/usr/lib/jvm/java-7-openjdk-amd64
PRODUCT_HOME=/home/openjdk/sources/jdk8_tl/build/linux-amd64_backup/j2sdk-image
ZIP_DEBUGINFO_FILES=0

InfraBuild

LANG=C
PRODUCT_HOME=/home/openjdk/sources/jdk8_tl/build/linux-x64-normal-server-release/images/j2sdk-image
ZIP_DEBUGINFO_FILES=0
ARCH_DATA_MODEL=64

Special steps for creating the C/C++ projects
Add the ‘make’ folder to the Source folder list by going to Project Properties > C/C++ General / Paths and Symbols > Source Location.
Click on Add Folder and select the /hotspot/make folder.

Then add an external builder by going to Project Properties > Builders
Click on New, choose Program as configuration type, click on OK and
call the builder ‘make_hotspot’.
Link it to /usr/bin/make by setting as the Location
Make the Working directory point to the make or makefiles folder – use the Browse Filesystem option to locate it.

For you’d like to do incremental builds, add “all” to the arguments list and for a full build add “clean” and “all” in order to determine the build action each time the project is built:
clean
all

Finally add the above enlisted environment variables for Hotspot to the External Builder configuration under the Environment tab, as shown in the screen-shot (enlists two of the remaining expected environment variables):

External Builder Environment Settings

External Builder Environment Settings

Now under Project Properties > C/C++ build
Under the Builder Settings tab
Check Generate Makefiles Automatically
Select External Builder as the Builder type (see at the top of the tab)
Keep the Generate Makefiles automatically checked.
Click on Apply.

Now Go to the Behaviour tab and uncheck the options [Build on resource save...] and [Build(incremental build)] options to ensure that the External builder configuration is used when the build action is invoked on a project.

Click on OK.

Build the project via the Project > Build Project option and wait for it to finish. At this point the project should be in a state to be build by either the Internal or the External Builder.

See How to build the Hotspot project for a more detailed approach.

g) Corba

Do the same actions as above for Corba as for the Hotspot project and translate names and locations that relate to the Corba project.

Build the project via the Project > Build Project option and wait for it to finish. At this point the project should be in a state to be build by either the Internal or the External Builder.

See How to build the Corba project for a more detailed approach.

h) JDK — sub-projects – Old Build

This build depends on successful builds of the Hotspot, JAX, JAXWS, Langtools and Corba packages.

Add the below lines to the build.properties file in case it does not already exist:

make.options=\
ALT_BOOTDIR=/usr/lib/jvm/java-7-openjdk-amd64 \
ALT_LANGTOOLS_DIST=~/sources/jdk8_tl/langtools/dist \
ALT_CORBA_DIST=~/sources/jdk8_tl/corba/dist \
ALT_JAXP_DIST=~/sources/jdk8_tl/jaxp/dist \
ALT_JAXWS_DIST=~/sources/jdk8_tl/jaxws/dist \
HOTSPOT_IMPORT_PATH=~/sources/jdk8_tl/hotspot/build/linux-amd64_backup/hotspot/import \
ALT_HOTSPOT_IMPORT_PATH=~/sources/jdk8_tl/hotspot/build/linux-amd64_backup/hotspot/import \
HOTSPOT_SERVER_PATH=~/sources/jdk8_tl/build/linux-amd64_backup/hotspot/import/jre/lib/amd64/server \
ALT_HOTSPOT_SERVER_PATH=~/sources/jdk8_tl/build/linux-amd64_backup/hotspot/import/jre/lib/amd64/server \
OPENJDK=true

Import a project using the Import a project from existing Ant BuildFile option via the New > Project > Other menu option and select ~/sources/jdk8_tl/jdk/make/eclipse/j2se/build.xml file for the j2se project.

Alternatively the whole project can be loaded as a C/C++ project following the same instructions as for the Hotspot project above. The above environment variables settings will be required to be added to the project.

Build the project via the Project > Build Project option and wait for it to finish.

Once all of these packages are build successfully, close down Eclipse.

For sanity check purposes please ensure that the individual packages / projects build from the command prompt and the OpenJDK project as a whole builds from the command prompt i.e.

cd ~/sources/jdk8_tl/[...project..]/make/    or   cd ~/sources/jdk8_tl/jdk/make/[...project..]/
make all

This is to ensure one process hasn’t negatively impacted the other. For a list of project names refer to the section at the top of page.

See How to build the JDK sub-projects – Old build for a more detailed approach.

i) JDK — sub-projects – Infrabuild

Do the same actions as above for the Hotspot project and translate names and locations that relate to the OpenJDK project. Import the project from /home/openjdk/sources/jdk8_tl/common/makefiles folder, rename the project to something like ‘OpenJDK’ instead of the ‘makefiles’ name given by default. Depending on the build system used, apply the below environment variable and argument list settings (does not require the traditional ALT_ ones anymore – instead they should all be unset).

LANG=C
PRODUCT_HOME=/home/openjdk/sources/jdk8_tl/build/linux-x64-normal-server-release/images/j2sdk-image
ZIP_DEBUGINFO_FILES=0

When setting up the External Builder setting for the Infrabuild system, you can apply one of the below entries in the arguments list:

images
clean images
images VERBOSE=”-d -p”
clean images VERBOSE=”-d -p”

Note: Please refer to http://openjdk.java.net/projects/build-infra/guide.html for further details on what the arguments mean in the Infrabuild system.

The rest of the instructions to setup the Hotspot project apply. Build the project via the Project > Build Project option and wait for it to finish. The above results in creation of the j2re and j2sdk images in the /jdk8_tl/build/linux-x64-normal-server-release/images folder (in folders j2re-image and j2sdk-image respectively).

Note: you can jump start the process by using the ready-made projects made available in the Github repo mentioned below. A clean build using the InfraBuild system would take an hour on a VM and under 15 minutes on a native machine – all this subject to various performance factors of a system. The Old build system is slower in this respect.

See How to build the JDK sub-projects – Infrabuild for a more detailed approach.


Full OpenJDK build Logs

See Full OpenJDK build Logs to view the logs produced from a full build action.


Full OpenJDK build output

See Full build output: artefacts for details on build outputs (artefacts) produced from a full build action.


Newly created Eclipse projects

Now you have a number of ready created Eclipse projects in your Eclipse workspace.

Go to the workspace folder where Eclipse creates the project files and settings i.e. into the /home/openjdk/workspace folder.

There are a number of folders each representing the project you have been working on, in each folder there are atleast two to four hidden files and folders such as:

.project
.cproject
.classpath
.settings

Copy these over to the folders for each of the respective packages under the ecproject folder in the respective folders as shown below.

~/sources/jdk8_tl/jaxp/ecproject/
~/sources/jdk8_tl/jaxws/ecproject/
~/sources/jdk8_tl/jdk/make/eclipse/j2se/ecproject/
~/sources/jdk8_tl/jdk/make/eclipse/jconsole/ecproject/
~/sources/jdk8_tl/jdk/make/eclipse/jmx/ecproject/
~/sources/jdk8_tl/jdk/make/eclipse/swing/ecproject/
~/sources/jdk8_tl/langtools/make/eclipse/langtools/ecproject/

An archive of the list of files that were modified across the openJDK system can be found at (include .cproject, .project, build.xml, build.properties, etc… files):

Github repo with directory structure of files and folders (last updated 18/09/2012) for both the Old Build and the InfraBuild system

In the Infrabuild folder in the repo, two new projects namely openJDK (images) and openJDK (images VERBOSE) have been included to build the whole OpenJDK system via the InfraBuild system.

Here is a list of packages which were not built during the process, they all have the necessary make and build scripts in them:

awt2d
jarzip
jdwpgen
world

Please provide any feedback on areas that work differently for you. If you have fixed an issue also let us know so that we can update the information here.

This blog has been inspired by a couple of JUG members working on the OpenJDK project, below are links leading upto them. Their instructions and systemic approach have helped in the process:

Netbeans projects for OpenJDK – Martijn Verburg
Netbeans projects for OpenJDK – Andrii Rodionov
Hacking Hotspot in Eclipse – Roman Kennke
Adding include paths to your C/C++ project – Roland
Sachin Handiekar – Screen-shots and other improvements.
Girish Balakrishnan – for reviewing and feedback on the Hotspot instructions.
Jonathan Gibbons (from the OpenJDK team) – Thanks for reviewing the Langtools section.

A number of other online resources and videos have also helped in the process.

About these ads

2 thoughts on “How to build OpenJDK projects in Eclipse (for Ubuntu 12.04 LTS)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s