The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


inder's Blog

Installing a Ubuntu Hardy Heron Java Development Environment on a USB flash drive

Posted by inder on July 6, 2008 at 12:16 PM PDT

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):

  1. sudo fdisk /dev/sdc
  2. Delete any existing partitions by typing "d". Type "p" to check that the disk is cleaned out.
  3. 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.
  4. Type "n" to create the second partition. Again, choose primary, with id 2. For size, choose default settings.
  5. Type "a", and select 1 to mark the first partition as the boot partition.
  6. 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.

Related Topics >> Linux      
Comments
Comments are listed in date ascending order (oldest first)

nice one.

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.

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.

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.

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.

Installing a Ubuntu Hardy Heron Java Development Environment on a USB flash drive

Posted by inder on July 6, 2008 at 12:16 PM PDT

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):

  1. sudo fdisk /dev/sdc
  2. Delete any existing partitions by typing "d". Type "p" to check that the disk is cleaned out.
  3. 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.
  4. Type "n" to create the second partition. Again, choose primary, with id 2. For size, choose default settings.
  5. Type "a", and select 1 to mark the first partition as the boot partition.
  6. 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.

Related Topics >> Linux      
Comments
Comments are listed in date ascending order (oldest first)

nice one.

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.

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.

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.

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.

Teaching Maven2 to use multiple source directories

Posted by inder on May 22, 2008 at 4:37 PM PDT
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.

Related Topics >> Java Tools      
Comments
Comments are listed in date ascending order (oldest first)

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.

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

Teaching Maven2 to use multiple source directories

Posted by inder on May 22, 2008 at 4:37 PM PDT
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.

Related Topics >> Java Tools      
Comments
Comments are listed in date ascending order (oldest first)

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.

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

NetBeans module for Java SDK for Google Checkout APIs released

Posted by inder on August 30, 2007 at 3:22 PM PDT
Do you write Web applications for selling things on the Web? Have you considered integrating Google Checkout to enhance the buying experience on your Website? Besides providing an easy Web-based console for merchants, Google Checkout also provides a powerful REST and XML based API to enable merchants to integrate their backend systems for order processing.

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.

Related Topics >> Java Enterprise      
Comments
Comments are listed in date ascending order (oldest first)

NetBeans module for Java SDK for Google Checkout APIs released

Posted by inder on August 30, 2007 at 3:22 PM PDT
Do you write Web applications for selling things on the Web? Have you considered integrating Google Checkout to enhance the buying experience on your Website? Besides providing an easy Web-based console for merchants, Google Checkout also provides a powerful REST and XML based API to enable merchants to integrate their backend systems for order processing.

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.

Related Topics >> Java Enterprise      
Comments
Comments are listed in date ascending order (oldest first)

Pet peeve with the Java 1.5 enhanced for loop

Posted by inder on May 24, 2007 at 4:15 PM PDT

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.

Related Topics >> J2SE      
Comments
Comments are listed in date ascending order (oldest first)

Pet peeve with the Java 1.5 enhanced for loop

Posted by inder on May 24, 2007 at 4:15 PM PDT

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.

Related Topics >> J2SE      
Comments
Comments are listed in date ascending order (oldest first)

Using Google Checkout SDK with Glassfish

Posted by inder on May 21, 2007 at 11:28 PM PDT

Google Checkout Logo 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:

  1. Download and install Glassfish.
  2. Download checkout-sdk-0.5.zip or a later version from its download page.
  3. Unzip checkout-sdk-0.5.zip file. This will create a directory named checkout-sdk-0.5.
  4. 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
  5. Copy checkout-sdk/checkout-sdk.jar to your WEB-INF/lib
  6. Copy checkout-sdk/web/WEB-INF/checkout-config.xml to your WEB-INF/ directory
  7. Edit your WEB-INF/web.xml and cut-and-paste the contents from checkout-sdk/web/WEB-INF/checkout-fragment-for-web.xml
    1. 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.
    2. Use Checkout SDK Javadocs to extend notification handlers
  8. Copy over the contents of checkout-sdk/web/checkout to a suitable directory in your application. For example, web/checkout
  9. Your application is now ready to use Google Checkout APIs. Deploy it on glassfish to test the integration
  10. 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.

Related Topics >> Java Enterprise      
Comments
Comments are listed in date ascending order (oldest first)

Using Google Checkout SDK with Glassfish

Posted by inder on May 21, 2007 at 11:28 PM PDT

Google Checkout Logo 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:

  1. Download and install Glassfish.
  2. Download checkout-sdk-0.5.zip or a later version from its download page.
  3. Unzip checkout-sdk-0.5.zip file. This will create a directory named checkout-sdk-0.5.
  4. 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
  5. Copy checkout-sdk/checkout-sdk.jar to your WEB-INF/lib
  6. Copy checkout-sdk/web/WEB-INF/checkout-config.xml to your WEB-INF/ directory
  7. Edit your WEB-INF/web.xml and cut-and-paste the contents from checkout-sdk/web/WEB-INF/checkout-fragment-for-web.xml
    1. 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.
    2. Use Checkout SDK Javadocs to extend notification handlers
  8. Copy over the contents of checkout-sdk/web/checkout to a suitable directory in your application. For example, web/checkout
  9. Your application is now ready to use Google Checkout APIs. Deploy it on glassfish to test the integration
  10. 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.

Related Topics >> Java Enterprise      
Comments
Comments are listed in date ascending order (oldest first)