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.

Downtime, Updates, and Glass!

2010

First off, sorry about the recent downtime. My (free) host had a failing hard drive. Naturally, my site was on that drive, and it took a while to move everything to another server and reconfigure it.

I recently finished a Visual Studio 2010 extension that automatically closes braces (because Microsoft still hasn’t implemented it, and there’s no way I’m buying something like ReSharper). Because I am boring and unoriginal, I have named it Brace Completer. You can find it in the software section.

I also updated my Opera/Firefox userscripts with a couple enhancements. The accented character shortcuts script loads a bit sooner on Opera, and the MangaFox script can now use session/localStorage to cache image urls, making things load faster if you return to a previously loaded chapter.

Lastly, I have an update for GlassCalc, which fixes an overflow error with base conversions, a freeze with long input strings of all the same letter, a bug with updates, and a few other things. The full changelog can be found here. Also, I decided that, for a program named GlassCalc, my calculator didn’t have nearly enough glass. I have now remedied this oversight.

[singlepic id=13 w=320 h=240 float=center]

Go to the Options->More Settings page and check Full Glass UI to turn it on. You’ll obviously need Vista or Windows 7 for it to work.

Speaking of things named GlassCalc, as it turns out, the name I chose in an inspired moment of uncreativity has been in use by an English software company for some 25 years. Whoops. They asked if I would link to their site, which I will gladly do here and now (as well as some other places around the site).

Glass Software UK
Glasscalc Ltd are the leading software developers in the specialist field of Pricing / Costing and Invoicing systems for the Glass Industry.

If you happen to be looking for software that deals with actual glass, go check it out!

Adsense, Without Blocking

2010

My web pages pause at ads for a moment. Why?

In some (but not necessarily all) web browsers, if you place a script in the middle of a web page, it has to be executed before the browser can continue rendering the page. The AdSense script is quite slim, but your browser still has to request the JavaScript file from Google, which could take a while depending your Internet speed. This means your pages might load up to the ad, pause a little while, then continue loading. Fortunately, there is a very simple way to keep scripts from blocking your content: put them at the end of the page. This way, all your content is loaded before the scripts are downloaded and executed. Unfortunately, this also puts all your ads at the bottom of the page, but with a little JavaScript, you can put your ads back where they belong.

How to fix it

First, you’ll need some sort of placeholder for where an ad should go. Use a div and set its id so you can easily find it with JavaScript. If you have multiple ads, number the ids so you can replace them all with a loop.

<div id="ad-0"> <!-- the first ad goes here --> </div>
<div id="ad-1"> <!-- a second ad goes here --> </div>

Now, place the AdSense JavaScript at the end of the page. Put each ad inside a div with an id so you can easily find it with JavaScript. Put the everything in a div with display set to none so your ads won’t briefly appear at the bottom of the page.

<div style="display:none">
  <div id="adsource-0">
    <script type="text/javascript"><!--
    google_ad_client = "pub-xxxxxxxxxxxxxxxx";
    /* Ad Name */
    google_ad_slot = "##########";
    google_ad_width = 125;
    google_ad_height = 125;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
  </div>
  <div id="adsource-1">
    ...
  </div>
</div>

Finally, use JavaScript to move each ad to its proper place. This script uses document.getElementById to find the ad and the placeholder, then it uses appendChild to move the ad into the placeholder div.

<script type="text/javascript">
numAds = 1;
for (var i = 0; i < numAds; i++) {
    source = document.getElementById("adsource-" + i);
    placeholder = document.getElementById("ad-" + i);
    placeholder.appendChild(source);
}
</script>

How well does it work?

Consider this entire site a live tech demo. Refresh the page and watch under the “Advertisements” header of the sidebar. After all of the content is loaded, the ads pop into place.

It breaks my layout!

With this setup, the placeholders initially take up no space, so they expand when the ad gets loaded. If this breaks your layout, you can set the height and width of the placeholder to the dimensions of the ad like this:

<div id="ad-0" style="width: 125px; height: 125px"> <!-- this placeholder takes up space! --> </div>

Edit (A bit later, still June 4)

Apparently, this is what I get for writing a post about AdSense. See? This is why we can’t have nice things.