Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.
Showing posts with label netbeans. Show all posts
Showing posts with label netbeans. Show all posts

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

Wednesday, June 4, 2008

Mysql : NetBeans 6.1 : OpenSolaris 2008.05

I am trying to install "glassfish - mysql bundled netbeans 6.1" on open solaris 05/08. During the installation , I got some Gtk warnings like :

(:1464): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkComboBoxEntry (need an instance of GtkEntry or of a subclass)

(:1464): Gtk-CRITICAL **: file gtkwidget.c: line 3236: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed

(:1464): Gtk-CRITICAL **: file gtkstyle.c: line 5879: assertion `style->depth == gdk_drawable_get_depth (window)' failed

(:1464): Gtk-CRITICAL **: file gtkstyle.c: line 5879: assertion `style->depth == gdk_drawable_get_depth (window)' failed

Anyway , during the installation of netbeans I have selected all default locations. thus mysql and glassfish were installed in my home directory.

I have tried to start mysql server with the following configuration :

[Click on the image to get larger view]


[Click on the image to get larger view]

but , after clicking 'start' I received an error like :

"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)".

Which means , Mysql server is not running at all. So , I tried to start it manually.
In terminal , I typed "mysqld_safe --user=mysql --log &" which results :

ritwik@ritwik:~$ cd mysql
ritwik@ritwik:~/mysql$ bin/mysqld_safe --user=mysql --log &
[1] 764
ritwik@ritwik:~/mysql$ nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /var/lib/mysql
bin/mysqld_safe[380]: /var/lib/mysql/ritwik.err: cannot create [Permission denied]
bin/mysqld_safe[388]: eval[1]: /var/lib/mysql/ritwik.err: cannot create [Permission denied]
STOPPING server from pid file /var/lib/mysql/ritwik.pid
tee: /var/lib/mysql/ritwik.err: Permission denied
080604 18:26:41 mysqld ended
tee: /var/lib/mysql/ritwik.err: Permission denied


[1]+ Exit 1 bin/mysqld_safe --user=mysql --log


From the result , I think some permission related factor is creating problems. That's why I changed permission of the above said directories as a super user.

Now "bin/mysqld_safe --user=mysql --log &" results :

ritwik@ritwik:~/mysql$ nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /export/home/ritwik/mysql/data


Thus MySql server is running and doing all desirable functions.

Tuesday, June 3, 2008

NetBeans 6.1 on OpenSolaris 2008.05

Open Solaris 05/2008 has an excellent feature of adding packages graphically and netbeans option is also there but I was trying to install it in the same I have done before. Because , NetBeans 6.0.1 will be installed if you execute "pkg install netbeans" or choose netbeans from package manager (IPS GUI) , but I want to install NetBeans 6.1.

During installation , I got some warnings / critical problems regarding Gtk. Those were like :

(:1464): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkComboBoxEntry (need an instance of GtkEntry or of a subclass)

(:1464): Gtk-CRITICAL **: file gtkwidget.c: line 3236: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed

(:1464): Gtk-CRITICAL **: file gtkstyle.c: line 5879: assertion `style->depth == gdk_drawable_get_depth (window)' failed

(:1464): Gtk-CRITICAL **: file gtkstyle.c: line 5879: assertion `style->depth == gdk_drawable_get_depth (window)' failed


otherwise everything was fine. "MySql" server was bundled with sxde 9/07 but that's not true for open solaris 05/08. so I decided to download and install MySql server. I downloaded "mysql-5.1.24-rc-solaris10-i386.pkg" and tried to install it in my system. I have used "pkgadd" command as root for installation , but at last the following error results :

## Executing postinstall script.
ERROR: 1004 Can't create file '/var/tmp/installCgaqqb/#sql2a8_1_0.frm' (errno: 13)
080603 23:51:00 [ERROR] Aborting

080603 23:51:00 [Note] /opt/mysql/mysql/bin/mysqld: Shutdown complete


Installation of system tables failed! Examine the logs in
/var/lib/mysql for more information.


and , "/opt/mysql/mysql/bin/mysqld --skip-grant &" results :

080604 0:05:33 [Warning] Can't create test file /opt/mysql/mysql/data/ritwik.lower-test
080604 0:05:33 [Warning] Can't create test file /opt/mysql/mysql/data/ritwik.lower-test
[1] 720
ritwik@ritwik:~$ 080604 0:05:33 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.

[1]+ Exit 1 /opt/mysql/mysql/bin/mysqld --skip-grant


I don't know what's the actual reason behind it.... may be the operating system is the reason.. as I was using an installer which is made for solaris 10 and I am using open solaris 05/08.

Anyway , under such circumstances I decided to install the Glassfish - Mysql bundled version of NetBeans IDE 6.1. I did it , got the same "Gtk" error during installation , otherwise everything was normal !!!!

Next : A minor problem while starting MySql server.

If you want to install Mysql in your open solaris 05/08 system , check out "web stack components" from "Open Solaris 05/2008 (part - IV)".

Friday, May 30, 2008

NetBeans 6.1 : Visual Web JSF Application

Hmmmm , there's something new !! Anyway getting started by New Project --> web --> web application. Give project name and location --> choose server --> select framework : visual web java server faces --> Finish. Here "page1.jsp" is your welcome page , (check out a green triangle before it which means that ! ). edit design / jsp / java code as you need. Here a new feature is added in 6.1 i.e ON DEMAND BINDING. "NetBeans IDE 6.1 features on-demand binding. Where components require Java coding, you must now manually add the binding attribute to components in a Visual Web JSF application. To do so, right-click each component and choose Add Binding Attribute. For more information, see the On-demand Binding Attribute Wiki."

Check out the following docs from NetBeans.org:

Developing a Visual Web JSF Application

Navigating Pages in a Web Application

Using Page Fragments

Converting and Validating Data in Visual Web JSF Applications

Understanding Scope and Managed Beans

Getting Started with Visual Web JSF Application Development

Tuesday, May 27, 2008

NetBeans IDE 6.1 : simple Web application

Now I have started developing web applications using NB 6.1 . Just click New project --> web --> web application. There's nothing new in setting up a new web project , I have followed the same as in 6.0.1 except an option for using a dedicated folder for storing libraries.
You can use a server of your choice : Apache Tomcat / GlassFish V2. Different frameworks are also available , select according to your need and start web programming.

As usual , "index.jsp" file will be created under Project name --> Web Pages --> WEB-INF --> index.jsp.This is your default welcome page of the program.you change the title , edit the body to write your own program. As html tags are used for designing a jsp program , netbeans provides a huge opportunity to write codes graphically. Just look at the Palette ([CTRL]+[SHIFT]+[8]) , you will find almost everything you need. If you put your mouse cursor on a button in the palette , html code will be appeared as tool tip text. simply drag and drop and design your html page."Html Forms" elements are used to take input from user and "HTML" elements are used for designing purpose.
Now write your first "Helloweb" program. Check out Docs and Support from netbeans.org : "Introduction to Developing Web Applications"

Playing more with "ejectDrive"

Now start playing with the same program by using the power of netbeans :

At first , click on the 'Runtime' of the following line
'Runtime.getRuntime().exec("eject cdrom");'
Now , you will get a yellow bulb in the left of the editor , same line position. click on it and it will tell you to "Assign Return Value to Variable". click on this line and
'Runtime.getRuntime().exec("eject cdrom");'
will be converted to
'Process exec = Runtime.getRuntime().exec("eject cdrom");'

We will use this exec variable later to perform some another job.

When you executing the command "eject cdrom" in a terminal window , (I am using sxde 9/07) you will get something like :
bash-3.2$ eject cdrom
cdrom /dev/dsk/c0t0d0s2 ejected


Now if you want to print this line : 'cdrom /dev/dsk/c0t0d0s2 ejected' from your program you need to add the following lines in your code :

BufferedReader in = new BufferedReader(new InputStreamReader(exec.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.print(line + "\n");
}


Now use netbeans code completion tool to write programs more easily.
Just write "Bu" and press [CTRL]+[SPACE] and you will get a drop down list of all which starts with 'Bu'. Use arrow cursors to find out BufferReader and press [RETURN].

In the same line when you are writing .....new InputStreamReader(exec.getInputStream()) , wait after writing 'exec.'..... and choose 'getInputStream' from the drop down box.

Now check out that 'BufferReader' and 'InputStreamReader' is underlined by red color which means there's an error in the code . you will also find a red bulb beside. Place your mouse cursor on it to get probable cause of the error and click on it to get possible solution. Just click on it and choose 'Add Import for java.io.BufferReader' etc.

So now everything is complete , indent / format using [CTRL]+[ALT]+[F] and save [CTRL]+[S].

Now 'Main.java' should look like :

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ejectdrive;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
*
* @author ritwik
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {
Process exec = Runtime.getRuntime().exec("eject cdrom");
BufferedReader in = new BufferedReader(new InputStreamReader(exec.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.print(line + "\n");
}
} catch (Exception e) {
System.out.print(e);
}
}
}


Run your program to get desirable output.

Monday, May 26, 2008

NetBeans IDE 6.1 : simple java application

Don't worry , I won't start with "HelloWorld".. rather say "EjectDrive"..yes, my first program in this IDE was to eject my cd/dvd drive.

It's quite simple by using a terminal window. Just execute a command "eject cdrom" , and your drive will be ejected. Now we will simply try to execute the command from a java program :

1. setup a new project. File -> new project -> java -> java application -> next

2. give a project name , say ejectDrive.

here I have noticed that NB 6.1 provides an opportunity to use a dedicated folder for storing libraries . I will discuss later how it's beneficial to make tasks more simple.

'create main class' & 'set as main project' will be checked automatically , just click 'finish'.

3. Main.java will be opened in the editor window. Here just add the following code under the main method :

try {
Runtime.getRuntime().exec("eject cdrom");
} catch (Exception e) {
System.out.print(e);
}


Now , your Main.java should look like this :

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ejectdrive;

/**
*
* @author ritwik
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {
Runtime.getRuntime().exec("eject cdrom");
} catch (Exception e) {
System.out.print(e);
}
}
}



4. Right click -> format or [ALT]+[SHIFT]+[F] to maintain proper indentation.

5. save. [CTRL]+[S]

6. Run. [F6]

and your cddrive will be ejected.

Next : Playing more with "eject drive"

NetBeans IDE 6.1

Netbeans IDE 6.1 has been released. For the past few months netbeans has been developed quite rapidly.. I was using version 6.0.1 before using the latest 6.1 version.

There's nothing new in installation process , except it's quite faster in comparison with previous releases. I have installed it in my solaris (solaris express developer edition 9/07) and linux (fedora 7) system.Click here to check out downloading and installation instructions.

Are you trying to install NB 6.1 in open solaris 05/08 ??? check out my experience.

Anyway , few things I have noticed just after the installation process :

* startup services : This IDE evolves a quick indexing of all necessary files from jdk installation directory , directories created under user's home etc. , performs a scanning task and compiles all source files from the open projects.
** Adds nb projects : All projects from "NetBeansProject" folder will be automatically added in this IDE as well as other NetBeans projects which resides in the same directory where netbeans is installed. If you have older versions installed in your system , nb settings can be imported in the latest version (just like previous releases).

*** Update notification : A popup message at the right hand corner will show you how many updates are currently available , apply them to make it up to date.

Click here to check out the features of Netbeans 6.1.

Next : Check out what's new in NetBeans 6.1..

Java application

Web application