Thursday, 3 April 2008

Portable Development - the JAVA trail

In the previous post most of the questions were only glanced at their surface. Some of the topics deserve more in depth exploration, which cannot be achieved in a single article. Despite that here we'll take one more fast look at the intersection between the PortableApps suite and two of the most powerful and widely used open source tools (IDEs) for JAVA development - NetBeans and eclipse.
I chose them not only because of their popularity but also because they are Platforms and represent two different approaches in creating a platform on which any other desktop application, rich with features can be built.
The glance here focuses on the possible ability of the IDEs to be made portable. As NetBeans is my favorite development tool of all. More articles concerning this one will be posted on its specialized blog.

The Environment
The first thing about development in any platform is preparing the environment - installing the tools involved in the development chain and eventually configuring them. In the JAVA case these are the Virtual Machine (JVM) - the interpreter of the byte code, the Compiler - the major development tool that translates the source code into the interpreted byte code, the documenting tool (javadoc.exe), the packaging tool (packager.exe) and lots of others complementary executables bound together into a JAVA Development Kit (JDK). The details on the ways of installing the Development Kit on portable device are available in this blog.
Once you have these tools detached from the host system, you have enough to simply start coding. In the PA Menu you may install Notepad++ Portable (it is an excellent editor for writing the code, which can be configured to act as a simple IDE for managing very small projects) and Command Prompt Portable (a console which can be configured according to your mobile environment). But even without them any system should provide such minimum tools. Whether you have enough privileges to change the environment variables is a different topic.

The Integrated Development Environments
Generally the eclipse IDE is easier because it has no installer, but the NetBeans' one is flexible enough to let you put it on the USB drive. So let's do it step by step.

*** eclipse ***
Download the ZIP archive of your preferred version from
Unzip it into the folder 'X:\PortableApps\'. Switch the drive letter to what's relevant for you.
The directory 'eclipse' is created there. Open the PA Menu and refresh it. Two new icons appear. Both of them start the IDE. The second one starts it in a console, so if you don't need this feature, just move the executable to some subfolder and refresh again.
If on the system where you set up your portable environment there is JRE or JDK installed already, if you run your newly imported eclipse, it finds the runtime environment and configures itself according to it.
That is nice of eclipse but is not very portable in our sense. In this case the first time you start the IDE on a system without JAVA, it will cry out for help, asking you to point to it where the JAVA is. So now we're gonna have to fix that.
What I normally would do in the past is to open the 'X:\PortableApps\eclipse\configuration\config.ini' file and change the value of the appropriate variable to point. These days situation is different. In the last version (europa or 3.3) overall configuration is made more sophisticated. Just open Window > Preferences... from the program menu and navigate to Java > Installed JREs and change the default location to point where you installed the JAVA SDK on your USB disk.
Now you're independent of the system specifics.

I'd like to mention here the Aptana Studio IDE. It is not meant for JAVA but is an ultimate Web development tool designed around coding in AJAX, Ruby (the 'On Rails' platform), PHP, etc. Part of its robustness is due to the fact that it is built on the eclipse platform. That's why it can be installed in the PA Menu exactly the same way as the eclipse IDE. And that is the reason I mention it.

*** NetBeans ***
Installing it is quite similar, but let's go through it anyway.
Run the installer you downloaded from (the latest stable release) or (the beta of the interesting new version).
I recommend the full version of the installer. After all you may not install everything but it is good to have the rest at hand (just in case).
Customizing what to install is possible on the first 'page' of the wizard. For default just press 'Next'. Then accept the 'License Agreement' and continue to the next page which is the most important step. Here you define the point of install and the source of the runtime. In both cases point to the appropriate folders on your portable device. Here is an example:
Install at: 'X:\PortableApps\NetBeans 6.1 Beta'
Get runtime from: 'X:\tools\jdk1.6.0_03'
Press 'Next' and then 'Install'. Now wait a while for the process to finish. The full installation takes up to 500 MegaBytes on the drive, but that doesn't count the two servers: Apache Tomcat 6.0.14 (about 12 MB more) and the GlassFish v2 (with its additional 142 MB). They both by default are installed in 'C:\Program Files'. If you find it sensible may move them to a portable location and reconfigure them accordingly (me, I wouldn't do it).
After pressing 'Finish' and refresh the PA Menu only the 'uninstall.exe' of the application appears - exactly the one you don't need at the moment.
What you can do is simply to switch places of the two executables. Go to the 'X:\PortableApps\NetBeans 6.1 Beta\bin' directory and move upfolder the 'netbeans.exe' file while placing here the uninstaller. Refresh again the PA Menu and that's it.