Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.

Tuesday, September 2, 2008

Build NetBeans IDE from source : getting started

Building Netbeans IDE from source is considered as the primary task of Netbeans developers. Here I am sharing my experience in working with Netbeans source. I built it on SXDE (solaris express developer edition) 1/08 which is installed in my laptop with 1 GB of physical memory and enough harddisk space. One thing I need to mention first that if you don't have a high speed internet connection the total process will take a lots of time and don't even try it with a dial up connection.

Now the requirements : JDK , Mercurial and Apache Ant.

JDK 1.5 update 13 was already installed in my SXDE 1/08 system.
SUNWmercurial-0.9.5 was also installed in my system.
Apache Ant version 1.6.5 was also there.

I tried to build with the above said configuration but faced lots of problems and finally build failed. So don't try to build if you don't have the following configuration :

JDK 1.5 update 13 is working fine and version 1.6 will not work !

Mercurial 1.0+ is recommended.

Apace Ant 1.7.0+ is also necessary.

If you don't know whether they are already installed in your system or which version is installed , check it first :

You may have multiple instances of jdk installed in your system. In my system version 1.5 and 1.6 both were installed. '/usr/jdk/instances' contained both 1.5 and 1.6 but '/usr/java' was linked to 1.6 . You may check the version of working java by executing '$java -version' , my output was something like :

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

It's not necessary that the output will be 1.5.0 , just make sure that 1.5 is installed in your system.

Mercurial version can be determined by : '$/usr/bin/hg -v'

first line of the o/p will contain the version name , my o/p was like :

Mercurial Distributed SCM (version 0.9.5)
------------- Many lines omitted --------------

Ant version can be determined in a similar way : '$/usr/sfw/bin/ant -v'

first line of the o/p will contain the version name, mine o/p was like :

Apache Ant version 1.6.5 compiled on November 29 2007
---------------------- Many lines omitted ----------------------

Now I will share how I updated mercurial and ant in my system but before that make sure that .profile file at your home directory doesn't contain '/usr/sfw/bin' as path variable. Otherwise you will get an error during build like : '~/main/nbbuild/build.xml:60: Class org.apache.tools.ant.taskdefs.condition.Not doesn't support the nested "antversion" element' .

I tried to update mercurial to version 1.0.2 . I downloaded it from http://www.selenic.com/mercurial/release/mercurial-1.0.2.tar.gz , extracted to /opt and tried to build it. But 'make' / 'gmake' failed with the same error : 'make: Fatal error in reader: Makefile, line 3: Unexpected end of line seen'. Same thing happened while I tried Mercurial version 1.0.1 (http://www.selenic.com/mercurial/release/mercurial-1.0.1.tar.gz) as well as Mercurial version 1.0 (http://www.selenic.com/mercurial/release/mercurial-1.0.tar.gz ). Finally I installed Mercurial 1.0 from Blastwave repository , by using '#pkg-get install mercurial'. If you don't know how to use pkg-get , Click here. I observed that mercurial-1.0 , Rev = 2008.04.03 was installed during the installation process , Python 2.5.1 and Berkleydb 4.4.20 was also installed as dependancy. After successful installation I checked the version by executing '$/opt/csw/bin/hg -v' and o/p was 1.0 . Then I removed '/usr/bin' from .profile at my home directory to avoid conflict between two hg versions and '/opt/csw/bin' was already added in my path.

Then I updated my ant version to 1.7.1 . I downloaded apache-ant-1.7.1-bin.zip from http://ant.apache.org/bindownload.cgi and extracted it to /opt. Then I added '/opt/apache-ant-1.7.1/bin' to my path :

'PATH=$PATH:/opt/apache-ant-1.7.1/bin'

and defined two environment variables ANT_HOME and JAVA_HOME :

'export ANT_HOME=/opt/apache-ant-1.7.1' &
'export JAVA_HOME=/usr/jdk/jdk1.5.0_13'.

You may check this out by executing '$env'.

Though I removed /usr/bin from my path and added /opt/csw/bin to my path , but '$hg -v' o/p was giving me version 0.9.5 .

Now you need to get a working copy by cloning the Netbeans repository. To do so , I executed :

bash-3.2$ /opt/csw/bin/hg clone http://hg.netbeans.org/main

you may also try main-golden repository which is guaranteed to always build by executing the following :

'bash-3.2$ /opt/csw/bin/hg clone http://hg.netbeans.org/main-golden'

It took a long time to be completed and produced an o/p like :

bash-3.2$ /opt/csw/bin/hg clone http://hg.netbeans.org/main
destination directory: main
requesting all changes
adding changesets
adding manifests
adding file changes
added 99216 changesets with 425778 changes to 94011 files
updating working directory
83779 files updated, 0 files merged, 0 files removed, 0 files unresolved

Now you will find a 'main' directory inside your home directory. If you have write access and want to push changes back you need to edit '~/main/.hg/hgrc' file. Initially it would be something like :

[paths]
default = http://hg.netbeans.org/main

Now edit this file so that it will look like :

[hooks]
pretxncommit.crlf = python:hgext.win32text.forbidcrlf
[ui]
username = username@netbeans.org
[paths]
default = http://hg.netbeans.org/main
default-push = https://username:password@hg.netbeans.org/main/

** Replace username and password with your original username and password.

Now if you have multiple instances of JDK installed in your system you need to mention JDK 1.5 as nbjdk.home. As some modules require additional heap to build, you need to increase javac's, the compiler's, heap size. For these purposes I created a new file '~/main/nbbuild/user.build.properties' and add the following lines:

build.compiler=extJavac
javac.compilerargs=-J-Xmx512m
nbjdk.home=/usr/jdk/instances/jdk1.5.0

Now you are almost done !! Just increase the heap size for ant as the default may not be enough by using a command like :

bash-3.2$ ANT_OPTS=-Xmx512m

Now the final building part :

bash-3.2$cd main
bash-3.2$ant

you must be connected to internet during this part as external binaries would be fetched from a server during first build. You will get an o/p like :

Buildfile: build.xml
clean-cluster-flags:
-jdk-pre-preinit:
-jdk-preinit:
-jdk-warn:
-jdk-presetdef-basic:
-jdk-default:
-jdk-init:
assure-ant:
-load-build-properties: bootstrap:
[mkdir] Created dir: /export/home/ritwik/main/nbbuild/build/antclasses
[javac] Compiling 4 source files to /export/home/ritwik/main/nbbuild/build/antclasses

After that I got a warning like :

[validate-hg-configuration] ======== WARNING ========
[validate-hg-configuration] You seem to be using a version of Mercurial older than 1.0.
[validate-hg-configuration] Please upgrade as your version may have serious bugs fixed in later versions.

Though mercurial 1.0 was installed in my system.

Anyway , build operation was going on smoothly for a long time .... but suddenly build failed due to hash check error in '/export/home/ritwik/main/o.n.soa.libs.xmlbeans/external/xmlbeans-2.1.0.zip'. I became confused and deleted all files from '/export/home/ritwik/main/o.n.soa.libs.xmlbeans/external' and tried to build again. Then it failed with a 'file not found exception' ... because I deleted the file i.e xmlbeans-2.1.0.zip which the build process was searching . Then I downloaded xmlbeans-2.1.0.zip from http://ftp.wayne.edu/apache/xmlbeans/binaries/ . Place the zipped file in '/export/home/ritwik/main/o.n.soa.libs.xmlbeans/external' and tried to build . But it failed again with another file not found error , it was searching for 'xmlpublic.jar' file to copy somewhere in the following path : '/export/home/ritwik/main/o.n.soa.libs.xmlbeans/external/xmlbeans-2.1.0/xmlpublic.jar' but it was not there. Then I found that 'xmlpublic.jar' file is present in the following path : '/export/home/ritwik/main/o.n.soa.libs.xmlbeans/external/xmlbeans-2.1.0/xmlbeans-2.1.0/lib' with 4 other *.jar files. I copied all 5 jars and paste them in the following directory : '/export/home/ritwik/main/o.n.soa.libs.xmlbeans/external/xmlbeans-2.1.0'. Then I tried to build again and this time everything was normal and finally it was successful.

Then I run '/export/home/ritwik/main/nbbuild/netbeans/bin/netbeans' , accept the license agreement and Netbeans IDE 6.5 'development version' was launched .

Everything I have already mentioned happened on yesterday. Today I tried to update my sources . I undergo the following way to pull other people's changes from the server into my repository :

bash-3.2$ hg pull -u
pulling from http://hg.netbeans.org/main

searching for changes
adding changesets
adding manifests
adding file changes
added 309 changesets with 514 changes to 414 files
414 files updated, 0 files merged, 33 files removed, 0 files unresolved

References :

http://wiki.netbeans.org/WorkingWithNetBeansSources

http://wiki.netbeans.org/HgHowTos

http://wiki.netbeans.org/ExternalBinaries

http://wiki.netbeans.org/HgMigration

3 comments:

  1. I am not able to build the code. What sud I do to fix this baag?

    ReplyDelete
  2. It's not clear to me what bug you are talking about.

    ReplyDelete
  3. It was very interesting for me to read that blog. Thanx for it. I like such topics and anything that is connected to this matter. I would like to read a bit more soon.

    ReplyDelete