Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Forum Archive > Main Support Categories > Desktop Environments
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Hello, Unregistered You are browsing a READ only archive of the main support categories pre 4/21/2008. You will not be able to post or reply any threads in this section.

Desktop Environments
Support for your Ubuntu desktop. Including Gnome, KDE and XFCE.

 
Thread Tools Display Modes
Old June 14th, 2006   #1
korny
5 Cups of Ubuntu
 
Join Date: Apr 2006
Beans: 21
Frustration with Java and gcj

Hi all,

I'm a Java developer, relatively new to Ubuntu, and I am finding the Ubuntu java packaging a complete nightmare. I'm mainly writing here out of frustration; though if others can point out an easy way to configure Java tools without doing all the work myself, I'd be a happy man

The basic problem is that while Ubuntu allows you to install Sun's Java, it defaults to gcj all over the place, and there is no easy way to change this. Surely if someone has chosen to install Sun's Java, Ubuntu could accept that decision and actually use it?

I understand the politics behind gcj, and I support the fact that it is the default java environment - the default option should be the completely free one. However, gcj is still severely limited in several areas - not least, the fact that it doesn't support Java 1.5 language features. This makes it not very useful, for me at least, in my day-to-day work.

However, in Dapper I can't get rid of the damn thing. Every java tool has gcj as a prerequisite, as well as a pile of other related libraries. Surely there is some way in apt for the system to recognise that I *have* a working JVM, and don't need to download all this extra stuff?

Worse, despite using the update-alternatives and update-java-alternatives mechanisms, many tools still use gcj. Eclipse is a case in point - as bundled with Ubuntu, it completely ignores the update-alternatives symlinks and uses gcj, unless you manually edit a config file. This may be ok if you are only doing gcj development, and not using a single tool or plugin that relies on Java 1.5 features - but it's not much use for the rest of us.

Ditto anything that looks for JAVA_HOME to identify a JVM - update-alternatives doesn't set JAVA_HOME, so such tools are also out of luck. Sigh. Suse used to have this working much more easily - it had a script to set JAVA_HOME and related environment variables on the fly, and then "/usr/bin/java" and related tools were scripts that interrogated JAVA_HOME and chose the right JVM for the current shell. Changing JVM could be done on a per-script basis. It looks like Suse 10 has moved to the update-alternatives mechanism however. Pity the person who wants to run two different JVMs at once...

In the end, I've given up on apt for my Java tools. I use it to install and update Java itself, and I use java-package to install other things like beta versions of Java 1.6, but I'm installing everything else by hand. That way I know they work, and won't be mysteriously running gjc behind the scenes, and I can tweak their startup scripts to run the right JVM, without worrying about collisions with automatic updates.

I know the real culprit is probably Sun, with their annoying restrictions on Java packaging - if they open-sourced Java, half the problem would go away. But given the fact that Ubuntu now allow you to install Sun's java, it'd be nice if it actually worked. :-/

- Korny
korny is offline   Reply With Quote
Old June 14th, 2006   #2
Nequeo
Gee! These Aren't Roasted!
 
Nequeo's Avatar
 
Join Date: Apr 2005
Location: Sydney, Australia
Beans: 200
Ubuntu 7.10 Gutsy Gibbon
Re: Frustration with Java and gcj

[edit] never mind... didn't read your entire post [/edit]
__________________
Insanity is all in the mind...
Nequeo is offline   Reply With Quote
Old June 15th, 2006   #3
vinodis
A Carafe of Ubuntu
 
vinodis's Avatar
 
Join Date: Jan 2006
Location: Bangalore
Beans: 112
Ubuntu 7.04 Feisty Fawn
Send a message via Yahoo to vinodis Send a message via Skype™ to vinodis
Re: Frustration with Java and gcj

where does it revert to gcj mysteriously?
I've set the env_vars in the /etc/environment and no issues as such.
vinodis is offline   Reply With Quote
Old June 15th, 2006   #4
mattkenn4545
5 Cups of Ubuntu
 
Join Date: May 2006
Beans: 38
Re: Frustration with Java and gcj

sudo update-alternatives --config java
mattkenn4545 is offline   Reply With Quote
Old June 15th, 2006   #5
mattkenn4545
5 Cups of Ubuntu
 
Join Date: May 2006
Beans: 38
Re: Frustration with Java and gcj

recommend doing

sudo update-alternatives --all

to check every alternative
mattkenn4545 is offline   Reply With Quote
Old June 15th, 2006   #6
korny
5 Cups of Ubuntu
 
Join Date: Apr 2006
Beans: 21
Re: Frustration with Java and gcj

Quote:
Originally Posted by mattkenn4545
recommend doing

sudo update-alternatives --all

to check every alternative
Take a look at update-java-alternatives - it's basically a wrapper around update-alternatives that runs it for all java binaries.

Mind you, as per my previous rant it only works for some programs.
korny is offline   Reply With Quote
Old June 15th, 2006   #7
pecanov
Way Too Much Ubuntu
 
pecanov's Avatar
 
Join Date: May 2005
Location: Macedonia
Beans: 55
Edgy Eft Testing
Send a message via ICQ to pecanov Send a message via Skype™ to pecanov
Re: Frustration with Java and gcj

You claim to be a Java developer, and yet it seems you haven't set up java before (no hard feelings).

If you don't want to update alternatives, or have problem with it, set JAVA_HOME in your bashrc or the global one, and prepend it at the same place to the PATH variable.
pecanov is offline   Reply With Quote
Old June 15th, 2006   #8
korny
5 Cups of Ubuntu
 
Join Date: Apr 2006
Beans: 21
Re: Frustration with Java and gcj

Quote:
Originally Posted by vinodis
where does it revert to gcj mysteriously?
I've set the env_vars in the /etc/environment and no issues as such.
I didn't mean to say that it reverts mysteriously - but several programs when you install them have gcj as prerequisites, which forces you to install gcj; and then they use gcj even if you have update-alternatives set to Sun's java. Eclipse is a primary example of this - as installed by Ubuntu, it picks the first jvm it can find in the file /etc/eclipse/java_home.

And yes, you can manually set JAVA_HOME etc. in /etc/environment - but it doesn't keep in sync with update-alternatives, and comes under the category of "guru knowledge" in my opinion - I'd never even heard of this file Also only *some* tools use JAVA_HOME.

A summary of what I've observed so far:
- You can set your JVM in (at least) 3 ways:
(A) - running "update-alternatives" or "update-java-alternatives", which set symlinks from /usr/bin/java* -> /etc/alternatives/java* -> /usr/lib/j2sdk...etc

(B) - setting JAVA_HOME, JRE_HOME, JDK_HOME etc to the correct paths, either in /etc/environment or in a shell script or .bashrc or the like.

(C) - modifying /etc/eclipse/java_home and/or /etc/jvm (or other obscure config files)

- Java tools in the ubuntu repositories tend to use some combination of (A) (i.e. look for java on the path) or (C) (i.e. read an obscure config file). Those that use (A) obey update-alternatives settings, those that use (C) don't.

- Java tools you install yourself tend to use (A) or (B) or both - i.e. Tomcat uses JAVA_HOME if it's set, otherwise it looks for java on the path. This seems to be fairly standard behaviour. (A) works with update-alternatives, (B) doesn't.

None of these options allow you to choose a JVM in Ubuntu without knowing which magic config files to edit, or which command-line tools to run.

And there are about 1000 howtos on the net about *which* config files and/or command line tools you should run - most of them wrong, or at least incomplete.

- Korny
korny is offline   Reply With Quote
Old June 17th, 2006   #9
beameup
Gee! These Aren't Roasted!
 
beameup's Avatar
 
Join Date: Dec 2005
Location: Louisiana
Beans: 172
Send a message via ICQ to beameup
Re: Frustration with Java and gcj

While using the Dapper flight series I installed Sun Java by following the instructions in the Wiki to create a deb package from the downloadable bin file. To install the updated version in Add/Remove will I have to uninstall the other first?

I went ahead and installed it. And this is what my java config looks like. Which one do I select? #1 or #4.
Quote:
There are 4 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /usr/lib/j2re1.5-sun/bin/java
2 /usr/bin/gij-wrapper-4.1
*+ 3 /usr/lib/jvm/java-gcj/jre/bin/java
4 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java

Press enter to keep the default[*], or type selection number:
Korny is right, It's not for the average Joe.

I use Moneydance financial software which requires Java. I had to use the installer with Java. It placed JRE1.5.04 in the Moneydance install folder. It doesn't see the newer java version. I'll inquire about that with them.
beameup is offline   Reply With Quote
Old June 18th, 2006   #10
beameup
Gee! These Aren't Roasted!
 
beameup's Avatar
 
Join Date: Dec 2005
Location: Louisiana
Beans: 172
Send a message via ICQ to beameup
Re: Frustration with Java and gcj

[BUMP] Dang!
beameup is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:03 PM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry