Netbeans IDE – Uncompilable Source Code exception

Posted on 12th March 2011 in Something Daily

So I’ve been working on a Java project recently, which, in terms of sheer lines of code, is pretty substantial. As such, I work on it a lot in different locations, and usually split the work between my two computers. Me being the efficiency freak that I am, I have found ways to ensure that the current version of the project is always accessible from anywhere on any system I’m using. That is, I keep the source files in the cloud (via Dropbox), so that every time I save a change in Netbeans it’s automatically uploaded, and I keep disk backups of the current files (done by a shell script every time I close a session). So basically the source directory that Netbeans looks at is just symlinked from Dropbox, while the class files are kept locally on each computer that I’m working on (apparently the Linux and Mac JVMs are different enough to require an annoying recompile if you don’t do this). But everything that I’m doing with this stuff is controlled by shell scripts.

The thing is, I started to notice that if I ever save anything in Netbeans when I’m not connected to Dropbox (that is, Dropbox fails to sync) I start getting errors about “uncompilable source code”. The identical code still runs just fine from the command line, but Netbeans can’t handle it. I finally found the answer to this issue today, though – it turns out that when Netbeans is set to compile every time the file is saved, a separate set of class files are created for debugging purposes. Certain things can cause these files to be corrupted and uncompilable, such as, I found out, a nonsyncing Dropbox containing the source files.

So to fix this, I first turned off the “compile on save” feature in Project Properties, then deleted closed Netbeans and deleted the directory “.netbeans/6.9/var/cache/index” (where the cache of extra class files is kept) and reopened. The directory is automatically recreated in a noncorrupted state when Netbeans reopens. The problem of uncompilable source code is gone now, with the one added annoyance of having to manually compile before running. Still, I’m glad my project runs.

The source of this new knowledge.

MacBook Pro Backlit Keyboard in Ubuntu Maverick

Posted on 4th January 2011 in Tutorials

I was browsing around a little while ago and it occurred to me that the keyboard backlight on my MacBook Pro 5,4 wasn’t working under Ubuntu 10.10 Maverick Meerkat. I found a few resources online to help with the problem, and it ended up teaching me a lot. I wrote a script that changes the numeric string stored in /sys/class/leds/smc::kbd_backlight/brightness, then set the script to be run every time the keylight increment/decrement buttons on the keyboard are pressed. Here are the steps I took, in case you want to try this for yourself.

I worked up a shell script that, depending on the string passed from the command line, either increments, decrements, sets to zero, or sets to 100% the value of the backlight brightness.

Go ahead and use the code, or write your own, I don’t care. You can either copy and paste from here into a file called keylight in /usr/bin, or download the file here.

Once you have /usr/bin/keylight on your system, run sudo chmod +x /usr/bin/keylight to make the script executable. You’ll know that you forgot this step if you get a “command not found” error when you try to run it.

To test the script, run sudo keylight full. The keyboard backlight should come on. To turn it off, run sudo keylight off. I use an alias to avoid the necessity of sudoing every time – that is, I added the line alias keylight='sudo keylight' to the /home/emmett/.bashrc file. Still, a password is required when running the script. Since we want this to be controlled with the keyboard, we have to override that somehow. This can be accomplished by adding the following lines to /etc/sudoers (run the command sudo visudo to edit this file).

Cmnd_Alias KEY = /usr/bin/keylight
%admin ALL = (ALL) NOPASSWD: KEY

(it’s hard to see, but there is an underscore between Cmnd and Alias – that is, Cmnd_Alias)

These lines tell the computer that, when running the keylight command, members of the admin group do not need to enter a password. With that accomplished, all that’s left is to create new keyboard shortcuts for the script. In System->Preferences->Keyboard Shortcuts, click “Add”. Fill the “Name” field with something like “Keylight up”, and enter sudo keylight up into the “Command” field. (Don’t forget the sudo!) Click OK, and change the hotkey for the command to the F6 key (XF86KbdBrightnessUp). Repeat the process for keylight down, keylight full, and keylight off. I use the F5 key for down, and add Ctrl for full and off.

Follow this process, and the backlight on your keyboard should work like it does under Mac OS X. At least, it does for me. Feel free to comment with feedback, comments, or additions you make to my code. Thanks for reading!