Sunday, 13 April 2008

Portable NetBeans - part II

Of course just placing NetBeans on USB drive and running it from there doesn't make it really portable. Why?
As most of the serious contemporary applications the IDE uses some deal of system awareness. That means it not only scans the host system (during installation) for where your Java is but it also takes account on the user's home directory, where the service information have to be stored.
So when the installer is started, if you monitor the contents of your user's directory in Windows, you'll see a new one created - '.nbi'. It stores the logs and configurations that let the installer, when started again, know what exactly have been installed on the previous occasions(s). That's not bad at all. On one hand you have a host environment that may serve you as a dock for your portable IDE. But on the other, it restricts the portability. This folder may be moved on the USB drive, but NetBeans installer will still search for it in the current user's home directory. That's not a catastrophe so far - you successfully installed the IDE already and most probably it won't happen again up till the next version.
Anyway, another and more important directory is created into the user's home the first time NetBeans is started - '.netbeans'. This is the actual configuration center for the IDE - updates are downloaded here, the current state of the application is preserved here, etc. In time this folder may become quite big in size. What's worse - this directory could leave a trace of your presence on the host system! Oops! That would be so unportable.
I feared so, that's why I made a test. I ran the IDE on a fellow's laptop. Before that I had been moved the '.netbeans' folder in a place such as 'X:\tools\netbeans\conf' on my USB memory. When started the update center I expected the '.netbeans' folder to be regenerated into the user's home. Nothing like this. I installed a module and the trace for this was written exactly where it had to be - in '
X:\tools\netbeans\conf\.netbeans\6.1\update-tracking' and the module was downloaded into 'X:\tools\netbeans\conf\.netbeans\6.1\modules'. It is still a mystery to me how this happened, because it is dumb to believe that things happen this way. On a second try it didn't work. Of course.
So, what is the right way? Well, I just opened the right file: 'X:\PortableApps\NetBeans 6.1\etc\netbeans.conf' and provided the correct value to the
netbeans_default_userdir variable on the second line:
netbeans_default_userdir="X:/tools/netbeans/conf/.netbeans/6.1"

Now with everything in place NetBeans starts and updates very portably.
Yet another 'prankster' always appears during the NetBeans startup - the '.netbeans-registration' directory. It regenerates anytime, anywhere. And always leaves a trace. It isn't much - just a small XML status file, but this is a trace after all. I don't mind to register my IDE, but no more than once is appropriate, I think.

Well, all these 'hacks' are just on the go. We can hardly ever expect an official version of Portable NetBeans from the community or SUN. If you're smart enough (and I bet you are) and you chase the Portable conditions then the sky is the limit, like they say. Not only the IDE but the Java itself can alway be made thinner and slimmer and encapsulated. It is only a matter of little effort and plenty of free time. And of course limitless imagination.

6 comments:

shajunxing said...

Hi, I've studied how to make netbeans portable for a long time too. I noticed the first comment line in netbeans.conf which shows that netbeans determines the user profile directory by user.home JVM parameter. So i tried to start netbeans.exe by "-J-Duser.home=XXX" but unfortunately failed, but some directies was actually created in XXX folder. Since user.home is determined by the USERPROFILE environment variable, I tried to set up this environment variable in the batch file such as "set USERPROFILE=XXX", but the same thing happened too. Confused...

johnniepop said...

Hi, shajunxing!
Shame on me (for the late answer too) but I did the ugliest thing possible. The ugliest but the most simple also. In the netbeans.conf file for the netbeans_default_userdir variable (v. 6.5 of the IDE) I hardcoded the path to the place on my USB drive where I placed the .netbeans folder - just like explained in the post above. It always works fine for me. And I always test if it's working by installing some new plugin - everything behaves as I expect it. Nevertheless I avoid using system variables when possible, especially bound to the host operating system.
I hope you've found the right decision by far.

Unknown said...

Hi, there!
Shame on You both! ;) It was standard error. Next time just read documentation. "Installation troubleshooting" 6.1 and 6.5. Eventually U could just change os user.
Best,
cooboosh

Agustin said...

I did install the 6.1 version on my USB, but now im trying to install the 6.5 version and I cant, once I finish the install and open the IDE, I cant open a new Java proyect

Valery said...

Hi,

there are good news coming with NetBeans 6.7 Release Candidate 1.

There is an option to download Platform-Independent Package as ZIP file and extract it to any folder on your system (USB disk!).

Run the executable file located in the netbeans/bin directory and accept the License Agreement.

The NetBeans IDE starts!

If the compatible JDK installation cannot be found, you might need to manually add the path to the JDK installation directory:

1. Open the netbeans.conf file located at netbeans/etc in a text editor.

2. Enter the location of the compatible JDK installation as the value of the netbeans_jdkhome option.

3. Save the netbeans.conf file and run the executable file at netbeans/bin.

Unknown said...

NETBEANS PORTABLE with jdk 1.6.0_18 and Wireless SDK 3.0 (J2ME): Made by myself:
http://www.mediafire.com/file/0j3mmjm3gz4/NETBEANS_IDE.part1.rar
http://www.mediafire.com/file/yzynlymxe2m/NETBEANS_IDE.part2.rar