`Which Java`?


I’m a little frustrated because I’ve been hitting some memorable distro-issues throughout the week and revisiting some of my old topics to help me through. Today I wanted to install Charles proxy so I can sniff HTTP traffic and rememberize all of the neat-o stuff I used to know about HTTP. Here’s one thing that used to bug me alot, Java explodes on linux. No matter what distro I tried and would inevitably hit a situation where Java would just blow up in my face. I’ll be running my IDE and it will just vanish. Or I’ll be running some app I just wrote and it craps out with VM error stack trace.That prompted me to see which Java I had installed in Mepis. A naive person would type “java -version” on the command line but after years of experience I learned that not only is that misleading it’s downright dangerous! If Java is officially installed (a process that varies from machine to machine and OS to OS and distro to distro) you have to understand that the system can pick a different version of Java than what you get on the command line. The command line is influenced by the $PATH while there are a number of different ways to invoke Java on your system. Consider hitting a page with an Applet? Java runs out of your Browser. Depending on which browser you run you’ll get a different JVM. Consider what happens when you click a Web Start link. You can have Firefox configured to associate it with one version of Java while your file manager (Windows Explorer, KWin, whatever) can associate it with another. Then there’s the executable jar thing. Once again window manager file associations can point someplace you never intended. Lastly there’s batch files and shell scripts. On Linux your $PATH can be overridden in your .bash_profile and/or your .bashrc while the $PATH assumed by your Window Manager is completely different.

So which Java do you get? On Linux you can literally type `which java` and it will tell you the path to the executable but that doesn’t help much. Try adding “ls -la” in front.

ls -la `which java`

Then you’ll see that this is a symbolic link to the actual (sometimes other sym link to the actual) executable. Keep following sym links until you get tired and you’ll find the true path to Java. This used to be controlled by and update-alternatives -config java command but I just tried that on Mepis and it doesn’t exist. I tried looking for update-alternatives under apt-get install update and got nowhere. I’m spilling all these details here because now I really don’t know `which java`???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s