11/27/2009

AppFuse Struts2 Tutorial with Eclipse / SpringSource Tools Suite

Excerpt from AppFuse's website:

AppFuse is an open source project and application that uses open source tools built on the Java platform to help you develop Web applications quickly and efficiently. It was originally developed to eliminate the ramp-up time found when building new web applications for customers. At its core, AppFuse is a project skeleton, similar to the one that's created by your IDE when you click through a wizard to create a new web project.

AppFuse builds on Maven to accomplish its goal. AppFuse + Maven can be used command line, creating our application with just a single line; but here we will be using Eclipse.

In this tutorial we'll go through the creation of a simple Struts2 web-application, which we'll extend later. We'll use SpringSource Tools Suite 2.2.1 (STS) which is a free tool based on Eclipse 3.5.1 with a pre-configured set of plugins useful for web-development. STS has the Maven2 plugin which we'll use to configure AppFuse for us.

So, grab a copy of SpringSource Tools from http://www.springsource.com/products/sts. After the installation, select File->New->Project... Type maven, and click Next:



Leave "Use default Workspace location" checked and click Next.



Enter struts in the filter, and select struts2-archetype-starter. This is a so called "Maven Archetype", a ready-to-be-used project template built around the Project Object Model (POM), which will create a starter application for Apache Struts 2.0. Click Next.



Now enter the following info:
  • Group Id: org.techmissive
  • Artifact Id: testdrive-struts
  • Version: 1.0.0
  • Package: org.techmissive.testdrive.struts
And click "Finish":



We have created our template project. Now Eclipse (I mean STS of course) will start downloading all our dependencies, and build the project for us. On OSX, we can see directly the Maven-log; on Windows we have to open the Console view (Alt+Shift+Q then C), and click the down-arrow next to the Open Console button on its toolbar (the window-like button left of the green lamp) and select Maven console to see what Maven is doing.



Included with this template is Jetty, a lightweight servlet container, which can be used to test our application locally without installing a full blown J2EE Server. Let's see how we can start it from STS.

Select Run -> Run Configurations... from the Menu, here we'll specify what happens when we start our application. Select 'Maven Build' from the list, and click on the New icon on the top of the window to create a new configuration.



To set the Base directory, click on Browse Workspace. Now click on testdrive-struts and OK. This sets ${workspace_loc:/testdrive-struts} in the Base directory field, which is a relative resolution from our workspace location.

To run Jetty, we have to run a given goal, so enter jetty:run-war in the goals field.

Replace the New_configuration default name with something more meaningful, like Run Jetty.



Click Apply to save, and Run to start the configuration we just created.

Now Eclipse is working again, starts to download all kind of stuff. But in the end proudly confirms the successful starting of Jetty:



Let's test if it works. Jetty is listening by default on the port 8080, so let's start a browser and check what is there. Start Safari and enter http://localhost:8080/testdrive-struts in the address field:



We have a running Web-application and we didn't have to write a single line of code. This is the main purpose of AppFuse: to provide us a skeleton application we can start working on without hours of hunting for the libraries, configuring them, etc. I just wish all the profiles would work the first time like this one...

11/12/2009

Skype on Ubuntu: No microphone on CM8738

I have just installed Ubuntu 9.10 "Karmic Koala" on a PC containing a C-Media Electronics Inc CM8738 sound-card. Quite oddly, although the microphone seemed to work thru Application->Sound & Video->PulseAudio Volume Control, there was no playback from the Skype call testing service.

Right clicking on the Volume control icon -> Sound Preferences -> Input seemed also silent. After fooling around a bit I realized that I need to set the proper input device not in PulseAudio but in alsamixer. Typing alsamixer in a terminal starts the mixer:

Press F4 to view the Capture controls, then the right arrow until you reach the microphone:

Now press the Up Arrow to increase your volume to an acceptable level (I have set it to the max just in case), and press ESC to exit from the mixer. This sets the microphone as the default input device with an adequate volume.

Go back to Skype and redo that call-testing (she has a beautiful accent, hasn't she?)

Hopefully it works now!











11/11/2009

Reinstall OSX, and re-partition from scratch with the installer for dual booting with Ubuntu

(This is the third part of the article Dual booting OSX and Ubuntu without REFIT)

My only problem with resizing the original OSX Snow Leopard installation is that it comes with lots of stuff I'm not using and this consumes quite some valuable disk-space. Do you really want to sacrifice 1.2GB on Language Transitions and 1.62GB on printer drivers if you don't need it? (Well, the printer drivers you may need, I have a Canon printer for which the driver is not in OSX, so I'll install separately anyway - thus I can get rid of this 1.62GB). Since I only have a 128GB drive to do the installation and I will install Logic Studio consuming some 60gigs, I prefer the reinstallation. Let's see how it works!

First and foremost, don't forget to back-up all your valuable data, since this method will destroy everything on the hard-drive. Don't forget: neither me nor anybody else can and will take responsibility for what you are doing on your own computer!

So pop in that CD (or USB key - did you know you can install Snow Leopard from an USB key?) and start the installation.

First select your language and click the arrow to proceed. In the "Install Mac OS X" window, don't continue just yet; first we will have to re-partition our hard drive. So click Utilities->Disk Utility. Click on your drive, and click on the "Partition" tab. In the "Volume Scheme" dropdown, select "4 Partitions". This will split your drive to four, equally sized partitions. Good enough to start with!

My preferred layout is the following:

osx As I will have Logic Studio installed which will take like 60 gigs, I will have to leave a huge partition for OSX. So I'll make it 74GB (I tell you how I came up with this number: I tried before and Logic just did not fit on 64GB :-) If you don't have any huge programs like Logic Pro or Final Cut, 20GB should do for the OSX partition with Office.
home Will be visible from both Ubuntu and OSX, containing the documents we are working with: videos, pictures, source-files, etc; thus, it should fill up the remaining space from all the other partitions. Since the HFS driver in Linux is not able to read/write journaled HFS partitions, we will have to change the type of this partition to non-journaled HFS. It should be non-case-sensitive as well, since Adobe products are fooled with case-sensitive file-systems. So, it will be "Mac OS Extended", which is "non-case-sensitive/non-journaled".
ubuntu The Ubuntu partition will contain the Linux OS. 16GB will do for Karmic Koala.
swap The swap partition is the virtual memory; you have to set the size depending on the amount of RAM you have. I have 4GBs, and since I want to use Hibernation I have to set it to at least 4GB (see [Swap partition size for 4GB RAM - Super User]). If hibernation is not needed, you can go away with 1GB as well.

You should come up with a layout of your own, depending on your actual situation, HDD size, OSX & Linux usages.
I have a 128GB drive, so this is how it will look like:
  • osx(74GB)
  • home(34GB).
  • ubuntu(16GB)
  • swap(5GB)
Click on the bottom-rectangle which says "Untitled 4". This selects the partition for the swap. Enter "swap" in the Name, MS-DOS in the Format, and 5GB in the Size field.

Click on the next rectangle, which says "Untitled 3". This is the partition for the Linux filesystem. Enter "ubuntu" in the Name, MS-DOS in Format and 16GB in the Size field.

Click on the next rectangle saying "Untitled 2". This is the shared partition. Enter "home" in the Name field, as size enter 34GB (or whatever you have calculated as your Shared partition size)

Click on the topmost rectangle which says "Untitled 1". This will be the partition of our OSX installation. Enter "osx" in the Name field; the size should be already fine since it equals to the remaining of all our previous partition-sizes.

Now you can click on any of the rectangles to verify your partition-sizes. If you are content, press Apply. This will do the partitioning in no time.

When it is finished, you can close Disk Utility. In the Install Mac OS X window, press Continue. Agree the Licence Agreement after reading it through, then select your "Macintosh HD" as a target disk. If you click Customize, you can remove the Printer Support if you don't have a printer or if have your own driver to install after OSX installation; as well as the Additional Fonts if you don't use those languages. I usually deselect the Language Transitions since I'm using OSX in english anyway. X11 I usually keep, but that's just because I may need it if I end up doing development in OSX.

So just click OK and Install.

After the OSX installation is finished, you can continue and Install Ubuntu 9.10 "Karmic Koala" on an already partitioned drive.











Install Ubuntu 9.10 "Karmic Koala" on an already partitioned drive

(This is the fourth part of the article Dual booting OSX and Ubuntu without REFIT)

To me it seems 64bit code runs smoother on today's hardware, so I'm using the 64bit editions if I have the chance. All Apple hardware containing Core2Duo (or better, e.g. Core i5, Core i7) processors is capable of running 64bit code; so here we're going to install Ubuntu 9.10 Desktop 64bit also known as Karmic Koala (under "Alternative download options" you'll find the 64bit edition). The nice thing is that it doesn't really matter: there is hardly any difference in setting up 32 or 64 bit Linux distributions.

Somehow installing Ubuntu thru USB didn't work for me on a Macbook Pro 4.1. So I have burnt the image to a CD and installed it from there: pop in and boot from the CD (keep pressing Alt when you turn on your Mac and select the CD), and select "English" then "Try Ubuntu without any change to my computer". Sounds careful doesn't it?

Ubuntu starts up as a live distro. Double-click on the icon Install Ubuntu 9.10. Select the language to use and click Forward.


Select your timezone and click forward.


Select your keyboard layout and click forward. On a mac, it makes sense to select USA - Macintosh.


Now comes the interesting part, partitioning. Select Specify partitions manually (advanced) and click Forward.


Since OSX is using GPT instead of MBR for partitioning our drives, you can see some strange things here, like the 200MB EFI partition (/dev/sda1) or the 134MB disk spaces between the partitions. This is fine, we just have to "see through the lines". If we write the OSX names next to the partitions everything will be clear:

/dev/sda1209 MBEFI
/dev/sda274356 MBosx
/dev/sda334000 MBhome
/dev/sda416000 MBubuntu
/dev/sda54131 MBswap

So, let's mount /dev/sda4 to "/" which will be the root of our Linux filesystem. Double-click on the line beginning with /dev/sda4, in Use as select EXT4 journaling filesystem, click Format the partition, in the Mount Point select "/" and click OK.


Now we're going to create a swap partition. Doucle-click on the /dev/sda5 line, select swap area under Use as, and click OK.


We can't select HFS in the installer, so we'll have to mount the shared "home" partition later on ourselves by the fstab file. For now, we have a root partition and a swap partition, so just click forward!


Fill in all the necessary parameters in the intimidating "Who are you" dialog and click forward again.


In the Ready to install dialog, click Install (GRUB will go into MBR, which is fine). The installation commences and will be finished in no time. Press Restart Now.

When the Mac starts up, you'll have to hold the Alt key for the operating system selector menu to pop up. Oddly the additional entry we have next to our Macintosh HD is Windows; apparently Apple thinks if there's anything next to its operating system, that will be Windows. So just select Windows and press ENTER and we are booting Ubuntu!

In the next post, we will discuss how to configure Ubuntu to have access to the Shared partition and we'll set up some symbolic links in both OSX and Ubuntu to store our Documents, Pictures, Music and Videos in the common folder, so that we have access to them no matter which one we start up.











Resize your existing OSX partitions to make some space for Ubuntu and a "Shared" partition

(For the background, see Dual booting OSX and Ubuntu on a Macbook PRO)

To squeeze Ubuntu to my Macbook Pro I actually prefer reinstalling from scratch since Apple installs quite some unused stuff. But, if you don't mind losing some gigabytes, just proceed here, this is the "less destructive" way to go since your original operating system (and thus your home directory with all your documents) remains intact if the partitioning proceeds without error.

Please take my word as warning: Although I'm using dual and triple boot computers for years and the described procedure works for me (in fact I'm doing it whilst writing this article), I can't take any responsibility that it will work for you as well, and I can't take responsibility for any damage or loss you may encounter. If you still choose to follow me, please, backup your home folder NOW.

I'll tell you a short story: about three years ago, I decided that EXT3 is the way to go on my 1.8TB RAID containing about 800GB of data. It was NTFS, and since there was no utility to convert NTFS partitions to EXT3 and I didn't have a 1TB drive at my disposal (at the time 300GB was the top HDD size, at least in what I could have bought for my hardly-earned money), so I decided to take the risk and proceeded without backup. Using GParted I planned to decrease the size of the NTFS partition to 900GB, and would have created a 900GB EXT3 behind it, would have copied everything to the EXT3, then would have deleted the NTFS & would have resized the EXT3 to use the whole drive, having 1.8TB again. If I'm not mistaken everything went well up till the last step: the NTFS was copied, was deleted, and the EXT3 resize failed.

Early version of GParted? Data inconsistency? No clue. But the process was stuck, and after a day (you can imagine that day!) I had to stop it and start looking for ways to retrieve my data. Fortunately I was able to get back almost everything from the deleted NTFS partition and by now I have external drives backing up my RAID with rsync regularly (and I'm thinking about migrating my backups to EC2 or another cheap cloud-provider); I have learnt from my own mistake, so you should learn too: MAKE BACKUPS when dealing with such sensitive issues like filesystem-resizing operations.

Let's go! Start Applications->Utilities->Disk Utility and click on your Hard Drive on the left panel. Now on the right side, click Partition.



If you have your original installation, probably you will have one big partition named "Macintosh HD" like me here. We will have to shrink this partition so that our little Karmic Koala fits here too. My preferred layout is the following:

OSX As I will have Logic Studio installed which will take like 60 gigs, I will have to leave a huge partition for OSX. So I'll make it 74GB (I tell you how I came up with this number: I tried before and Logic just did not fit on 64GB :-)
Shared Will be visible from both Ubuntu and OSX, containing the documents we are working with: videos, pictures, source-files, etc. Thus, it should fill up the remaining space from all the other partitions. Since the HFS driver in Linux is not able to read/write journaled HFS partitions, we will have to change the type of this partition to non-journaled HFS. It should be non-case-sensitive, since Adobe products are fooled with case-sensitive file-systems. So, it will be "Mac OS Extended", which is "non-case-sensitive/non-journaled".
Ubuntu The Ubuntu partition will contain the Linux OS. 16GB will do for Karmic Koala.
Swap The swap partition is the virtual memory; you have to set the size depending on the amount of RAM you have. I have 4GBs, and since I want to use Hibernation I have to set it to at least 4GB (see [Swap partition size for 4GB RAM - Super User]). If hibernation is not needed, you can go away with 1GB as well.

I have a 128GB drive, so this is how it will look like:
  • OSX(74GB)
  • Shared(34GB).
  • Ubuntu(16GB)
  • Swap(4GB)

Before starting to partition the drive, I advise to sit down in front of an empty paper and try to come up with the proper numbers of your own. If you only go to the net with OSX, and you'll just install OpenOffice, 16GB should do for the OSX partition. Ubuntu is also quite happy with the 16GB, so if you sacrify 1GB for SWAP (in case you don't mind Ubuntu's hibernation), you can allocate all the remaining space to the SHARED partition, since it can contain all your documents, pictures, movies, music; reachable from either Ubuntu or OSX. The main advantages of this setup are:
  • if you happen to reinstall either OSX or Ubuntu later on, and you only store your data on the shared partition, you won't lose anything
  • you only have to work out a regular backup-procedure to the SHARED partition, since everything on the OSX and UBUNTU partition can be regenerated by a reinstallation.
To create the partition layout (don't bother with the size just yet - we'll change that in a sec), we will have to click on the rectangle representing the HDD (which says "Macintosh HD"), and then click the [+] sign next to the dimmed "Option" button, which makes a new partition. This results in two partitions:



Now click on the bottom rectangle on the left side ("Macintosh HD 2" on the picture) and click on the [+] sign again. We have three partitions:


Click on the bottom rectangle again ("Macintosh HD 2 2" above), and [+] again. We have four partitions finally:


So far, so good - we will just have to fix the sizes and the names now. Apple's Disk Utility is a tricky one, since if we change the size of a partition on top, it also changes the size of the partitions below. So we'll go from the bottom.

Click on the last partition on the left side ("Macintosh HD 2 2 2" above) Triple click on the Name textbox to select its contents and enter the new name: "Swap". Although the name we enter here will be erased with the filesystem itself when we install Koala, we'll enter the names so that we clearly see what we are doing. The format can stay since we'll delete this partition anyway (and we don't have the choice to select Linux Swap anyway), click on size and enter your preferred swap size. I will enter 4.4GB, and I hope this fixes the hibernation which didn't work in previous installations. Press Enter to update the rectangles:


Three more to go. Click on the rectangle above the one we just worked with ("Macintosh HD 2 2 1" above) to select it. This is the partition for the Linux Operating System. Enter a descriptive "Name" used only whilst partitioning: "Ubuntu". Format can stay again since the partition will be erased anyway by the Ubuntu installer. The size is 16GB. Enter:


With me yet? Let's go. Click on the rectangle "Macintosh HD 2 1", and enter "Shared" in the Name: field. Now click on the Format drop-down list and select "Mac OS Extended" (Do you remember? This is the non-case-sensitive/non-journaled HFS stuff from above, so that Linux can read and write it). The size is 34GB (or whatever your Shared partition size will be). Now press Enter and the rectangles will be updated:


Now you can freely click on any of the rectangles (e.g. partitions) to verify their size. If you are satisfied with the results, click Apply.


Smart Snow Leopard confirms the non-destructive manner of our operations. Since you have already made plenty of backups of your data, you can click on the Partition button right? After making sure your backups are intact, click Partition to proceed.

Now OSX verifies the disk, and executes the partitioning. In a couple of seconds/minutes, you'll see the results:



Now you can proceed to Install Ubuntu 9.10 "Karmic Koala" on an already partitioned drive.