Putting Netbeans AppData in the Right Place

2010

If you use Windows Vista/7 and Netbeans, you’ve likely seen a .netbeans and .netbeans-registration folder appear in your user directory. Netbeans is a very nice piece of software, but like many open-source programs, it goes by the mistaken belief that application data always goes in the home folder. This is perfectly normal for Linux, but Windows is not Linux. Windows application settings go in the AppData folder. It is possible to get Netbeans to store its settings in the right place, and it isn’t too difficult.

This guide will show you how to put Netbeans settings in the right place for Windows Vista/7, but you can also use it to put the settings directories anywhere you want on any system. I’ll assume you are using Netbeans 6.9. If not, change the version number where appropriate.

Find netbeans.conf

Open an explorer window and find the directory where Netbeans is installed. The default location is C:\Program Files\Netbeans 6.9 (C:\Program Files (x86)\Netbeans 6.9 for 64 bit systems). Inside it, there should be a folder called etc and inside that, a file called netbeans.conf. Run an instance of your preferred text editor as administrator (you won’t be able to save the file otherwise) and open netbeans.conf in it.

Change netbeans_default_userdir

The second line of netbeans.conf defines the settings directory. Change it to look like this:

# ${HOME} will be replaced by JVM user.home system property
netbeans_default_userdir="${HOME}/AppData/Roaming/Netbeans"

If you move your .netbeans and .netbeans-registration folders to this new location, Netbeans will pick up your settings, but it will still create the same two directories in your user directory and it will ask you to register again. This is because there are actually two options you need to change. The second one is a little harder to find.

Define -J-Duser.home

Line 6 of netbeans.conf defines a bunch of options, each starting with -J. You need to add another option to this line. Before the quote at the end of the line, add this: (replace USERNAME with your username)
[code lang=”text” light=”true”]-J-Duser.home=C:/Users/USERNAME/AppData/Roaming/Netbeans[/code]

Your netbeans.conf file should look something like this now.

# ${HOME} will be replaced by JVM user.home system property
netbeans_default_userdir="${HOME}/AppData/Roaming/Netbeans"
 
# Options used by NetBeans launcher by default, can be overridden by explicit
# command line switches:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true -J-Duser.home=C:/Users/USERNAME/AppData/Roaming/Netbeans"
# Note that a default -Xmx is selected for you automatically.
. . .

And now you’re done! Netbeans should no longer clutter your user directory with its settings.

4 thoughts on “Putting Netbeans AppData in the Right Place

  1. Great stuff – I have a profile ‘limit’ of 30meg in my User directory, however the Local Settings / AppData folder (ironically also within the User directory) in unlimited.

    Quick question for you though – I’m on Windows XP and whilst most of this is still quite applicable there are spaces in the directory, i.e. C:/Documents and Settings/{username}/Local Settings/Application Data/.

    Suggestions for how to cater for these spaces in the .conf file?

  2. That’s a good question. I’m not sure, but I have a couple things to try.

    First, try escaping the spaces with a backslash like this:
    C:/Documents\ and\ Settings/. Netbeans seems to like Unix path syntax, so that might work. If it doesn’t, try enclosing the path in single quotes. I’m not sure how Netbeans deals with nested quotes in its conf file, but it’s worth a shot.

  3. BIG BIG THANK YOU!

    I have been searching a lot to change the home path of netbeans. Now my Netbeans is portable and runs from a stick!

    Hint: the command line switch also handles relative paths! (i.e. -J-Duser.home=../userdir)

Leave a Reply

Your email address will not be published. Required fields are marked *