Monday, October 08, 2007

Risk and Java (changing your compiler)

I've recently been playing obsessing over a program which is essentially the game of Risk. For those of you who don't know (there have been a surprising number of people who didn't), Risk is essentially a board game where the objective is to dominate the world. You play against any number of players to try to capture territory and hopefully take the entire board. However, to me, it's HARD!!! I am utterly horrible at it and get beaten every time by the Easy AIs. However, I'm trying to get better.

Anyways, getting this baby to run was a long and arduous process (as have been most java programs on Ubuntu). However, there's always that one quick and simple solution that you've never known about which makes that horrible task easy as pie. And I believe I have found it. When running Risk, I noticed that for some reason it's broken in Java 1.4.2. However, for Java 5 and 6, it works perfectly. From the graphical perspective, it's easy to run a .jar file with a different compiler, just right click and select "Run with Sun Java 6". However, from the command line, I've always been plagued that the "java" command brings up the 1.4.2 compiler. I've searched everywhere in vain for a solution to this, because the typical process of linking the binary to the /usr/bin folder didn't exactly work, and something always went wrong. Well, I gave up for a while, until about, ohhhh..... twenty minutes ago. Then I decided to do a search on the Ubuntu forums, and sure enough, someone found a way to switch the compilers. And I'm going to show you how to do it now.

It's all done with a nifty tool called update-java-alternatives. Now, in order to use update-java-alternatives, you'll need to be root, so prepare your "sudo"s. Probably the first thing you want to do is check out what types of Java you have, you do that by typing
sudo update-java-alternatives -l

This will show you what different compilers you have. Here's an example from my computer:
java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
java-6-sun 63 /usr/lib/jvm/java-6-sun
java-gcj 1041 /usr/lib/jvm/java-gcj
I'll show you how to change it to Java 6. As you can see, the name for Java 6 is "java-6-sun". So basically all you have to do is type
sudo update-java-alternatives -s java-6-sun
And voila! Your compiler and libraries will all change to Java 6. Now, if I ever get stuck again, be sure to point me to this post. And I hope this was useful to you all too.

1 comment:

yasumoto said...

Ahhhhhhhhhhhhhhhhh.

It's so addicting ~_~

darn you for showing me how to get it to work. But thanks :)