Bug#445006: maven2: Selects first JRE found, ignoring alternatives

Paul Cager paul-debian at home.paulcager.org
Sun Oct 21 22:07:13 UTC 2007


Michael Koch wrote:
> On Tue, Oct 02, 2007 at 06:37:55PM +0200, Krzysztof Sobolewski wrote:
>> Package: maven2
>> Version: 2.0.7-1
>> Severity: normal
>>
>> I have two Java packages installed: sun-java5-jre and sun-java6-jre.
>> The latter is selected as /usr/bin/java by update-java-alternatives.
>> Now when Maven starts, it tries to select $JAVA_HOME by looking
>> into places where it might find Java (/usr/lib/jvm), apparently giving priority
>> to Sun packages. Unfortunately, in my case, it selects java-1.5.0-sun,
>> because it comes up first. This is mostly fine, but creates problems when,
>> for example, I'm compiling a program that uses newer APIs.
>>
>> The start script should probably first try to determine where
>> /usr/bin/java (or even `which java`) comes from.
> 
> The problem is that in the past not all JVM implementations worked for
> all usecases. That is why we implemented a way to guess a working JVM.
> This is wrong when new runtimes come up or change directories where they
> are installed. Using /usr/bin/java would probably work for Maven but
> /usr is no suitable setting for JAVA_HOME.
> 
> I dont really know what a good solution might be here. Probably its
> using /usr as JAVA_HOME and /usr/bin/java as Java virtual machine and
> let the local admin decide which runtime to use.
> 
> What are the opinion of others about this?
> 
> 
> Cheers,
> Michael

At the very least mvn should select later Sun runtimes in preference to
older ones.

For the benefit of other users looking at this bug log, I'd better point
out that you can explicitly set JAVA_HOME and mvn will not override the
setting. E.g.

	export JAVA_HOME=$HOME/jdk1.6
	mvn install


I've done some experimenting with maven, leaving JAVA_HOME blank but
setting JAVACMD=/usr/bin/java. You can certainly compile & assemble
maven with that configuration, but I suppose there might be some plugin
that depends on JAVA_HOME.

What about if we follow this algorithm to determine  JAVA_HOME (assuming
it is not already set)?

    (1)  Keep following the symbolic link /usr/bin/java until you get to
a plain file.

    (2)  Traverse up the directory tree until you are in a directory
where there is a "lib/tools.jar" file.

    (3)  If step (2) fails, then try traversing up the tree until you
find a directory with a "bin" subdirectory.

E.g. if
	/usr/bin/java -> /etc/alternatives/java
and
	/etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
set JAVA_HOME=/usr/lib/jvm/java-6-sun





More information about the pkg-java-maintainers mailing list