inder's Blog
Installing a Ubuntu Hardy Heron Java Development Environment on a USB flash drive
USB flash drives are really cheap these days, so I decided to create a portable environment that contains all my favorite applications, as well as Java IDEs and utilities. This is attractive since I can boot up any computer with this thumb drive, and have the same environment to work with. Besides, it is kind of cool.
You would think that this would be as easy as booting from the install disk of Ubuntu, and choosing USB disk as the target drive. Alas, it is not so. Ubuntu will try to install Grub which will be unable to boot from your USB disk. Moreover, I started running into problems with using the same USB disk at different computers. So, I searched around and found some excellent articles at debuntu.org and by Ryan Cloke. Both were written for the prior version 8.04 of Hardy Heron but are still largely appropriate. There were a few typos in the instructions, so I decided to reproduce instructions here with my edits, as well as add instructions related to setting up the Java development environment.
Prepare the USB Disk
Get a USB disk, at least 1 GB in size. I got an 8GB one since then I dont have to worry about conserving disk space for a while.
These instructions assume that you already have a Linux installation to use to prepare the USB linux installation. If you know how to do this with Windows, please share instructions as comments to this blog.
The first step is to partition the USB disk using fdisk. But to use fdisk, you will need to identify the device associated with the USB disk. You can do so by using fdisk itself:
sudo fdisk -l
Scan output for entries similar to this.
Disk /dev/sdc: 8017 MB, 8017412096 bytes 255 heads, 63 sectors/track, 974 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0xcb527ec4 Device Boot Start End Blocks Id System /dev/sdc1 * 1 95 763056 83 Linux /dev/sdc2 96 974 7060567+ 83 Linux
As you can notice, the disk /dev/sdc is 8GB that matches with my USB disk size. So, /dev/sdc is the correct device for my USB disk. Note that it is very important to identify the correct device. If you choose /dev/sda you will probably overwrite your existing hard disk losing all data and the OS on it!).
In my case above, I already have the USB disk properly partitioned. But you will need to do the same if you haven't already done so (Note that this will erase ALL the data on the disk, so back up anything important before executing these instructions):
sudo fdisk /dev/sdc- Delete any existing partitions by typing "d". Type "p" to check that the disk is cleaned out.
- Type "n" to create a new partition. Choose primary, with id 1. For size, choose the default starting track, but for end use +770M instead of a track number. This will create a disk of size 770MB, just enough to hold the live CD image needed for booting. You can choose to increase this a little bit, but making it larger has no benefit since the contents of this partition will never change. The second partition is what needs to hold all of your data and future updates, so make that occupy the rest of the space.
- Type "n" to create the second partition. Again, choose primary, with id 2. For size, choose default settings.
- Type "a", and select 1 to mark the first partition as the boot partition.
- Type "w" to write these changes to the USB disk and exit fdisk.
Now we need to format these partitions:
sudo mkfs.vfat -F 16 -n UbuntuLive /dev/sdc1 sudo mkfs.ext2 -b 4096 -L casper-rw /dev/sdc2
Prepare the Ubuntu Installation
Download the Hardy Heron 8.04.1 ISO image from Ubuntu website. I chose the 32-bit i386 image (ubuntu-8.04.1-desktop-i386.iso) because it is going to run on almost all CPUs. The first step is to mount the downloaded iso image.
sudo mkdir -p /media/iso sudo mount -o loop ubuntu-8.04.1-desktop-i386.iso /media/iso
Copy the contents of this image to a temporary directory (/home/inder/hardy-usb in my case):
mkdir -p /home/inder/hardy-usb sudo cp -rf casper dists install pics pool preseed .disk isolinux/* md5sum.txt README.diskdefines casper/vmlinuz casper/initrd.gz install/mt86plus /home/inder/hardy-usb/
Next, we will modify this installation to fix some bugs specific to USB disk installation.
cd /home/inder/hardy-usb/ mv isolinux.cfg syslinux.cfg sudo vi syslinux.cfg
You should replace the contents of this file with the following:
DEFAULT usblive GFXBOOT bootlogo APPEND file=/preseed/ubuntu.seed boot=casper initrd=initrd.gz quiet splash -- LABEL usblive menu label ^Start Ubuntu and save changes to USB kernel vmlinuz append file=/preseed/ubuntu.seed boot=casper persistent initrd=initrd.gz quiet splash -- LABEL live menu label ^Try Ubuntu without any change to your computer kernel vmlinuz append file=/preseed/ubuntu.seed boot=casper initrd=initrd.gz quiet splash -- LABEL live-install menu label ^Install Ubuntu kernel vmlinuz append file=/preseed/ubuntu.seed boot=casper only-ubiquity initrd=initrd.gz quiet splash -- LABEL memtest menu label Test ^memory kernel mt86plus append - LABEL hd menu label ^Boot from first hard disk localboot 0x80 append - DISPLAY isolinux.txt TIMEOUT 300 PROMPT 1 F1 f1.txt F2 f2.txt F3 f3.txt F4 f4.txt F5 f5.txt F6 f6.txt F7 f7.txt F8 f8.txt F9 f9.txt F0 f10.txt
Save the file, and move on to the next step of fixing another bug in initrd.gz:
cd /home/inder/hardy-usb/ mkdir initrd_old cd initrd_old gunzip < ../initrd.gz | cpio -i --make-directories cd scripts sudo vi casper
Now, search for "mount ${cowdevice} -t ${cow_fstype} -o rw,noatime,mode=755 /cow". Remove "mode=755". So the line should look like this:
mount ${cowdevice} -t ${cow_fstype} -o rw,noatime /cow || panic "Can not mount $cowdevice on /cow"
After your have modified and saved the casper script, we need to repack the initrd file system.
cd .. find ./ | cpio -H newc -o > ../initrdnew cd .. sudo rm initrd.gz sudo mv initrdnew initrd sudo gzip initrd sudo rm -rf initrd_old
Copying Ubuntu to the USB disk
sudo mount /dev/sdc1 /media/usb cd /home/inder/hardy-usb/ sudo cp -rf .disk * /media/usb sudo umount /media/usb
Make the disk bootable
sudo syslinux -f /dev/sdc1
If you had made the mistake of trying to install Ubuntu directly from the CDROM, you will need to get rid of Grub. You can do so by installing Lilo to overwrite MBR:
sudo lilo -M /dev/sdc
Yay, you have the USB disk with Ubuntu. Now reboot the PC with the USB disk plugged in. You may have to select the bios setting to boot from the USB. On my laptop, I have to press F12, and on my home desktop, I have to press F11. You can also make the USB disk as a higher priority boot device.
Configuring the Ubuntu Installation
Boot up your PC from the USB disk. The system will boot into the default Ubuntu account. Open a terminal and run sudo passwd to change the root password.
Create a user account for yourself by using the System|Administration|Users and Groups menu. Ensure that in the create account screen, you have given this user the permissions to administer the system.
Disable the automatic login to the ubuntu user. Select System|Administration|Login Window menu. Select the Security tab, and unselect "Enable Automatic Login" and "Enable Timed Login". Note that you can still go to the ubuntu user by typing Ctrl-Alt-F1. I could not figure out a simple way to prevent the system from automatically logging in ubuntu user. If you know how to do this, please share that as comments to this blog.
Prevent Ubunutu from hibernating. Launch sudo gconf-editor. Go to apps|gnome-power-manager and uncheck the can_hibernate option. This setting didn't really work on my system though.
Configure Ubuntu to allow software from multiple repositories. Go to System|Administration|Software Sources Menu. Under the Ubuntu tab, choose "Community-maintained Open Source Software (universe)". Also, choose "Software restricted by copyright and legal issues (multiverse)". I also unselected the "Source code" option hoping that it may save me precious space on my USB disk by avoiding source-code for programs.
At this time, you may want to update your system with the latest versions of the various packages from the System | Administration | Update Manager menu. However, be selective in updating especially if you have a USB disk less than 2GB in size. The reason being that all the new packages that you install will be installed on your second partition, while the original packages will remain on the first partition. You may still want to upgrade commonly-used packages such as firefox. Also, dont bother trying to remove any of the unused packages since, again, they are on the first partition, and will not really free up any space on the second partition.
Install flash player for firefox. This is useful if you want to play YouTube videos.
sudo apt-get install flashplugin-nonfree
You may also want Firefox configured such that it does not use the USB disk for storing caches. For that, start firefox, and type about:config in the URL bar. search for cache, and set browser.cache.disk.enable, and browser.cache.offline.enable properties to false.
Installing Java
Ubuntu does not come pre-installed with Java. Unfortunately, there are some bugs in Java packaqes, so just using apt-get will give you some weird errors regarding libjli.so. Here are steps to fix this problem (instructions adapated from swik.net):
sudo su // switch to administrator role apt-get install sun-java6-jdk ln -s / /cow export LD_LIBRARY_PATH=/usr/lib/jvm/java-6-sun/jre/lib/i386/jli dpkg --configure -a
Run javac --version to ensure that the JDK installed correctly.
You can also install openjdk-6-jdk package instead. In that case, make sure that you adjust LD_LIBRARY_PATH accordingly before running dpkg.
Install other useful tools such as subversion and maven:
sudo apt-get install maven2 sudo apt-get install subversion
Installing Eclipse Ganymede
Download Eclipse from eclipse.org or issue the following command from command-line:
wget http://ganymede-mirror1.eclipse.org/technology/epp/downloads/release/gan... tar xvfz eclipse-jee-ganymede-linux-gtk.tar.gz sudo mv eclipse /opt/
You can now run eclipse from /opt/eclipse/eclipse. I also installed a short-cut for Eclipse on my menu-bar. You can choose the icon images for Eclipse from /opt/eclipse/plugins/org.eclipse.platform_3.3.100.v200806172000/. You may also want to update or add Eclipse plugins at this time.
Once you have a configuration you are pleased with, you may want to create a backup so that you can restore it in case anything goes wrong. I did this by plugging-in the USB disk in my other linux desktop, and then using the dd command:
sudo dd if=/dev/sdc1 of=/home/inder/hardy-working-disk1.iso sudo dd if=/dev/sdc2 of=/home/inder/hardy-working-disk2.iso
You can restore this by issuing the dd commands in reverse:
sudo dd if=/home/inder/hardy-working-disk1.iso of=/dev/sdc1 sudo dd if=/home/inder/hardy-working-disk2.iso of=/dev/sdc2
That concludes this rather long blog. It took me several installs and reinstalls to get it right, but the results are worth it. I am enjoying my USB linux installation and using it to write this blog.
Have you installed linux on USB disks as well? If so, share your experiences as comments to this blog. Thanks for reading.
- Printer-friendly version
- inder's blog
- 3184 reads
Teaching Maven2 to use multiple source directories
For project Gson, which is a library to convert Java objects to JSON and vice-versa, we use Maven2. We are also using Javacc to generate a JSON parser, but we had to modify the generated source-code to hide the generated classes. This meant that we had two source directories, one under src/main/java and another under src/generated/java. I tried hard to find out how to convince maven to use both the directories for compilation, but most websites really advise you to use multiple modules. In maven1.x, there seemed to be some support for it through maven:addPath but nothing in Maven2.
Finally, I did find a solution for Maven2 in this and this thread, and thought I would share it here. Essentially, you define an include section in your build section of pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<includes>
<include implementation="java.lang.String">src/main/java/**/*.java</include>
<include implementation="java.lang.String">src/generated/java/**/*.java</include>
</includes>
</configuration>
</plugin>
See pom.xml of Gson for more details.
Have you run into a similar issue? Did you also find the answer hard to search? How did you solve this problem? Share your thoughts as comments to this blog. Thanks for reading.
- Printer-friendly version
- inder's blog
- 5173 reads
Comments
by brianf - 2008-05-22 19:40
This is one way to accomplish the goal, however the build-helper-maven-plugin is the generally accepted way to add additional source folders to a build. It also lets you do some things like attach random files to be installed/deployed, etc.--Brian
Apache Maven PMC
http://blogs.sonatype.com/brian
by brianf - 2008-05-22 20:40
On second thought, the compiler config above may cause problems with other plugins such as IDE integrations. The build-helper-maven-plugin really is the correct way. I wrote more about it here.NetBeans module for Java SDK for Google Checkout APIs released
We provide convenient libraries and sample code for various languages including Java, C#, Perl and PHP. But for Java, we go the extra mile. We provide an open-source project Google Checkout Java SDK that provides convenient Java-based handlers to deal with the XML messages sent by the Google Checkout APIs notifications and callbacks.
Of course, tools can make this process even easier. So, I am happy to announce the public availability of the first version of a NetBeans module that provides a wizard-driven interface to integrate the Checkout SDK in any Web project. Here are the instructions to download and install this plugin module in your NetBeans IDE.
We hope to continue enhancing this module based on developer feedback. So, share your experiences with Google Checkout APIs, SDK or this module as comments to this blog. Thanks for reading.
- Login or register to post comments
- Printer-friendly version
- inder's blog
- 1300 reads
Pet peeve with the Java 1.5 enhanced for loop
I love the enhanced for loop construct introduced in Java 1.5. It makes the code look clean, and saves us from dealing with iterators or array indices. But since it is essentially syntactic sugar, it does create iterators behind the scenes as necessary. This can result in insidious bugs since if the passed collection or the array is null, your for loop will throw a NullPointerException. Here is an example:
import java.util.List;
public class ForLoopTest {
public static void main(String[] args) {
List<String> items = null;
for (String item : items) {
System.out.println("Item:" + item);
}
}
}
When this program is run, it will throw a null pointer exception.
I think it would have been better if the for loop did a null pointer check on the collection before trying to iterate over it. Granted, it will have a little bit of overhead, but I think the cost is justified because it is really common for people to not check for null values before invoking the for loop. I dont expect the semantics to get changed now because of backward compatibility concerns, so dont hold your breath expecting a change. But still, what do you think? Did the language designers make a mistake? Share your thoughts as comments to the blog.
- Login or register to post comments
- Printer-friendly version
- inder's blog
- 3188 reads
Using Google Checkout SDK with Glassfish
Google Checkout is a Google service that enables a faster, safer and more convenient way to shop online. Online merchants can implement Google checkout on their websites, and then they do not need to worry about managing credit-cards information and privacy of user accounts. Besides, Google provides free credit-card processing until the end of 2007 and will later provide credit for adwords expenses in free credit card processing. It is trivial to implement an HTML version of the Google checkout process. However, Google also provides a REST-based XML API that can be used to automate order processing. In this blog, I will discuss how to use the Java SDK for Google Checkout to easily implement the XML API integration with Google checkout in your Web applications. You can then deploy your application on GlassFish or Tomcat to handle REST events.
The Checkout SDK provides a library jar and an XML configuration file that you will need to embed in your Web application. You can then configure your action handlers that will receive notification of various order processing events from Google as a user places an order. Here are the steps that you will need to follow:
- Download and install Glassfish.
- Download checkout-sdk-0.5.zip or a later version from its download page.
- Unzip checkout-sdk-0.5.zip file. This will create a directory named checkout-sdk-0.5.
- The top-level index.html has instructions on using the SDK. You can also browse the Javadocs for the classes contained in the SDK at docs/javadocs/index.html
- Copy checkout-sdk/checkout-sdk.jar to your WEB-INF/lib
- Copy checkout-sdk/web/WEB-INF/checkout-config.xml to your WEB-INF/ directory
- Edit your WEB-INF/web.xml and cut-and-paste the contents from checkout-sdk/web/WEB-INF/checkout-fragment-for-web.xml
- If you need to add additional handlers to process checkout notifications, edit checkout-config.xml and change default value of the handlers to your classes.
- Use Checkout SDK Javadocs to extend notification handlers
- Copy over the contents of checkout-sdk/web/checkout to a suitable directory in your application. For example, web/checkout
- Your application is now ready to use Google Checkout APIs. Deploy it on glassfish to test the integration
- Login to your Google checkout merchant account, click on Settings tab, and then click on Integration on the left menu. register the URL for your notification service in the API callback URL textfield. For example, if glassfish was running your application at http://foo.bar.com:8080/myapp then, the registration URL will be http://foo.bar.com:8080/myapp/notification
That is it! Try it out today, and share your experiences as comments to this blog. We will be try our best to improve the checkout SDK to enable easy implementation by your Web applications. Thanks for reading.
- Login or register to post comments
- Printer-friendly version
- inder's blog
- 1332 reads
JavaOne sessions on Java EE 5 puzzlers and Google Checkout

JavaOne 2007 is right around the corner, and I am participating in two sessions there. The first one is based on my work at my previous employer, Sun Microsystems. This session will present tips and tricks on using Java EE 5, and is patterned after the popular Java Puzzler sessions by Josh Bloch.
My other session is related to using Google Checkout API in Java applications. In this session, we will describe how Java developers can use this API to enable payments for selling products on their websites. The integration can be as simple as an HTML FORM post, or a heavy duty one for integration with order processing systems using a REST based API. We will also demonstrate how the popular Web 2.0 Pet Store application can be modified to use Google Checkout.
When neither presenting or attending other sessions, I will be handing out goodies at the Google booth in the pavillion! So if you are coming to the conference and would like to meet up, drop by the booth or at either of the sessions. If there are any specific topics you would like us to cover in the sessions, you are welcome to share them as comments to this blog. Thanks for reading.
- Login or register to post comments
- Printer-friendly version
- inder's blog
- 679 reads
Moved on...
This blog is on a personal note. After being at Sun for 10 years, I have now left Sun and joined Google. I am currently working on Google Checkout, Google's solution to make online shopping faster, safer and convenient. If you have ideas on how to achieve these goals better, share them as comments to this blog.
When I joined Sun, it was my dream company in regards to the culture and the quality of work. It certainly delivered on the promise. I am proud to be part of the team that created the Java EE Platform. I enjoyed working with superbly smart and caring people on projects such as Java Web Server, Java Proxy Server, J2EE RI, Java BluePrints, Java EE SDK and Java Application Platform SDK. I also got wonderful opportunities to interact with the broader Java community, and make numerous friends. Thank you Sun for all these wonderful gifts! I will continue to remain involved in Java (as Google uses Java extensively), but less so in Java EE.
- Login or register to post comments
- Printer-friendly version
- inder's blog
- 467 reads
What is the difference between Java Application Platform SDK and Java EE SDK
- Java EE 5 SDK: This bundle contains the Java EE 5 compatible Sun Application Server. This is same as GlassFish V2 beta. Additionally, it contains Java EE 5 API docs, a short tutorial, BluePrints, and samples. This bundle comes in two forms: with JDK (JDK 6) or without JDK.
- Java Application Platform SDK: This bundles contains all the contents of Java EE 5 SDK and includes the following additional runtime components: Sun Web Developer Pack Release 1, Open ESB 2.0 Beta, Java Portlet Container 1.0, Sun Java System Access Manager 1.0. This bundle also comes in two forms: with or without JDK.
- Java EE 5 Tools Bundle: This bundle includes Java Application Platform SDK, NetBeans 5.5.1 Beta, and NetBeans Enterprise Pack. This bundle does not contain JDK.
So, how do you decide which bundle to choose? Here are some guidelines:
- Download the Java EE 5 SDK bundle if you prefer command-line tools instead of NetBeans IDE, and are only interested in writing Java EE 5 applications.
- Download the Java Application Platform SDK bundle if you prefer command-line tools instead of NetBeans IDE, and are interested in writing applications that use Java EE 5 with additional components. The SWDP component provides support for writing Web 2.0 applications, the OpenESB component enables development of composite applications that use an Enterprise Service Bus (ESB), Java Portlet Container enables development of portlets and, finally, Access Manager enables using Web services security technologies.
- Download the Java EE 5 Tools bundle if you prefer using NetBeans IDE for developing Java EE 5 applications with additional features contained in the Java Application Platform SDK. In addition to regular Java EE application development, this tool provides visual development of composite applications using a BPEL editor, and easy configuring of Web services security.
- Login or register to post comments
- Printer-friendly version
- inder's blog
- 1924 reads
Are the various bundle options confusing? Do you have suggestions on how we can make them better? Share your thoughts as comments to this blog. Thanks for reading.
Announcing the release of Java Application Platform SDK Update 3 Preview
As the tech lead for the project, I am happy to announce the availability of the new version, Update 3 Preview, of the Java Application Platform SDK. This version includes the following enhancements:
Sun Java System Application Server 9.1 Beta: Sun Java System Application Server has been upgraded from version 9.0 UR1 Patch 1 to 9.1 Beta. This version includes support for clustering, HTTP/EJB session persistence using in-memory replication, Web services interoperability technology (WSIT), and Java Business Integration (JBI) support. Other changes include a redesign of the administration tool and an automated update mechanism.
Sun Web Developer Pack Release 1: Sun Web Developer Pack helps you to leverage emerging web technologies and techniques to create interactive and dynamic web applications for the enterprise. This toolkit is a collection of technologies for Ajax, scripting and REST-based services development supported by a NetBeans plugin that simplifies the design and development of rich Internet applications.
Open ESB 2.0 Beta: Open ESB has been updated from the earlier 1.0 version to 2.0 Beta. This version significantly enhances composite application development through a JBI-based integration platform fully integrated with the application server. Support has been added for clustering and XA resource recovery. JBI components included in this release are: Service Engines for BPEL, Java EE, XSLT, Intelligent Event Processing, and SQL; and Binding Components for File, FTP, HTTP, JDBC, JMS, SMTP, and WebSphere MQ protocols.
Portlet Container 1.0: The Portlet Container has been updated from the earlier 1.0 beta version to 1.0 FCS.
Sun Java System Access Manager 7.1: Sun Java System Access Manager has been updated from the earlier 7.1 beta version to 7.1 FCS. Read Securing Communications in Web Services: A Tutorial.
The Java EE Tools bundle was also refreshed to take advantage of the updated SDK Update 3 contents. This bundle contains the NetBeans IDE 5.5.1 Beta with the Enterprise Pack along-with the Java Application Platform SDK contents.
All in all, lots of interesting new capabilities to work with. So, what are you waiting for? Download it here and share your thoughts on this release as comments to this blog, or at the SDK forum.
- Login or register to post comments
- Printer-friendly version
- inder's blog
- 473 reads
Can GroupThink result in poor decision making in strong open-source communities?
I recently came across a great article on GroupThink of Irving Janis. GroupThink is a behavior pattern that results in inferior decision making by a group of smart people when the cohesiveness of the group is too high. It happens because of a strong desire of the people to preserve the harmony in the group even if at the cost of better decision making.
Open-source projects are also typically run by groups of smart individuals who all have come together to solve a common problem. Sinc the team is working towards a shared goal, often voluntarily and to attain a higher ideal, the cohesiveness can be high. Moreover, for certain high-profile projects, the desire of the group members to remain associated with the group is strong because it gives them prestige and satisfaction due to the project's impact on the society.
As the article describes, cohesion in the group is a necessary but not sufficient condition for GroupThink. It also requires structural faults in the group because of poor leadership, lack of process and norms. Finally, for the group to slide into GroupThink, a provocative situational context needs to exist such as a recent failure, high stress or low self-esteem.
Have you seen an open-source group slide into GroupThink? Have you had experiences in an open-source project where the group collectively made some poor decisions just to preserve the group harmony? Share your thoughts as comments to this blog! Thanks for reading.
- Login or register to post comments
- Printer-friendly version
- inder's blog
- 653 reads




Comments
by keeskuip - 2008-07-09 00:14
OK, now I see it. sdc2 is used for Live CD Image. Is it not possible to add the iso file to sdc1 and then mount it? Or should it be a writable filesystem.by inder - 2008-07-08 12:00
Yes, it should be sdc (I have updated the instructions). sdc2 is needed because that is where the OS is booted into. sdc1 just keeps the Live CD image, which is read-only. All of your OS updates, and user home directories, etc are kept on sdc2.by keeskuip - 2008-07-08 10:48
Good story! Coincidentally last weekend I gave it a try (to install ubuntu on an epia) and it almost worked. A few questions: 1. After the step 'Make disk bootable' you switch from sdc to sdb. I assume this is a mistake? 2. Why do you need sdc2? It doesn't look like you use it and I would like to keep my flashdrive vfat.by vjsjvm - 2008-07-07 12:35
I am glad to see this type of article on Java forum. I have been doing this for some time now and found the following site indispensable! http://www.pendrivelinux.com/ The whole purpose of this site is 'Easily run Linux from a portable USB device'! Do check it out.by awaisbajwa - 2008-07-08 07:14
nice one.