Author Archive

Cross-platform JNI (Java Native Interface) with NetBeans

jni.jpgRecently I had a programming challenge in that I estimated a feature for this Java application that needed to know whether a certain program was running, and if it was running, terminate it.

Of course, in Java, it cannot be done in a cross-platform way. You can certainly launch a process in Java, then terminate that process you created, but you cannot know if a certain process is running and terminate that. To do this, you will need to have native code, and the way Java interfaces with your native code is through JNI (Java Native Interface).

In subsequent blog posts, I will write about how I coded this “Process Manager” JNI library using NetBeans — creating a process management library that can can return a list of running processes (and their process ids), as well as terminating the process by process id. The libraries I created were implemented in C, using NetBeans, on the Mac OS X, Windows, and Linux (Ubuntu) platforms using NetBeans 6.0.1.

It turns out it was easiest in Linux: you can easily list all the running processes through Java code. Processes are directories under “/proc”, with the directory filename as process id. Inside the directory itself is a text file with the filename of “status”, and the first line contains the process name. Of course to terminate this process by process id, you will still need to use native code.

Technorati Tags: , , , ,

NetBeans for Ruby on Rails on Mac OS X

nb-logo-frontpage.gifIf you have NetBeans 6.0 and you want to use the bundled JRuby, you might as well get 6.0.1 if you want NetBeans to handle updating the JRuby Gems for you (after changing the permissions of the JRuby gems directory of course, see below). NetBeans 6.0 has an OutOfMemory stack problem when trying to update the gems. The latest available Rails for JRuby Gems is 1.2.5 I believe (the bleeding edge as of this date is 2.0.2).

Of course, if you are using  OS X’s included Ruby, just go to your command line and update Ruby gems normally (make sure you update rails with all its dependencies). Make sure to also update your environment.rb (in your Rails project configuration) to reflect the version of Rails you will be using.

When installing NetBeans, the whole bundle is installed using user “root” (read, write, execute privileges) and group “admin” (read and execute privileges only). The JRuby package is installed “inside” the NetBeans app bundle, and it has the same permissions. The current “user” needs to have “write” permissions to this JRuby directory, for NetBeans to update the gems:

  • /Applications/NetBeans/NetBeans 6.0.1.app/Contents/Resources/NetBeans/ruby1/jruby-1.0.2/lib/ruby/gems/1.8

Either that, or you run NetBeans as root. If you want only users from the admin group to have access to this feature of NetBeans, do a “sudo chmod -R g+w <dir>”, or if you want everyone to have this write access, just do a  “sudo chmod -R a+w <dir>” where <dir> is the directory path I referenced above.

Well, if anyone has trouble running NetBeans with Ruby on Rails, post a comment — I might have encountered your problem and solved it already, so I might be able to help.

Technorati Tags: , , ,

Re-evaluating my Digital SLR

I have a Pentax K10D. It’s been a year since I bought it, and I love it — but I think its time to let it go and sell it. No, it’s not because the Pentax K20D is coming out! :)

Frankly I need a smaller camera with RAW, and the Canon Powershot G9 fits the bill. No, I am not going to buy it yet, but sometime in the future hopefully. What sealed it was reading Nick Devlin’s experience with it at Luminous Landscape. I came to the realization that what has stopped me more than once in lugging my equipment around is its size. I definitely want RAW, and no point and shoot up to now has that capability.

I feel that the important thing is taking photos, and lots of them at this stage in my photographic development, not super equipment.

Technorati Tags: , ,

The end of “once a day” blogging

Announcing: “once a week” blogging.

Once a day in retrospect was too ambitious: the posts that came out of it were wasteful, they did not contribute anything except for glorified advertisements for products mainly, I felt. My main goal was to improve my writing, but I wanted to do so as long as I could come up with “some” original thought at least, and not just re-hashing some news I came by from other blogs.

Hopefully my post for next week will be more fruitful in this regard! It is easier to develop this habit by making it easier for me to do, then hopefully increase the frequency when I have kept my writing discipline up.

Technorati Tags:

Sanyo Eneloop Rechargeable Batteries

Sanyo Eneloop Battery Charging Kit with 2,000 mAh AA Rechargeable Batteries (4-Pack)

What’s the difference between the Sanyo Eneloop Rechargeable Batteries  and regular rechargeable batteries, you ask? They retain their charge longer. Bet you didn’t know that when you charge a rechargeable battery, and you don’t use it, the charge drains?

I’ve had it happen one too many times. Of course, after charging regular non-Eneloop rechargeable batteries and storing it for the next time I need to use it, and then needing to use it, they held no charge. But of course, I said, these batteries were probably never charged. Which of course was not true, I just forgot that I did charge them!

This is especially handy if you need to store extra batteries for your digital camera or flash in your photo bag, and knowing that it will reliably hold a charge when you need it.

Technorati Tags: , , ,