I consider this a bug, and you probably don't. I sometimes need to use ant with jvms that are not distributed by gentoo, and this worked for years. Now in ant-core-1.6.5-r14 /usr/bin/ant expressly runs java-config to force the value of JAVA_HOME. I hate that behavior. I want /usr/bin/ant to honor JAVA_HOME however I set it.
Yeah, and we prefer to keep the packages in portage working correctly... :P
We're not using JAVA_HOME anymore because it's tied to your env, you have to source /etc/profile after changing it, it's not flexible enough - if you set JAVA_HOME to 1.4 jdk, apps needing 1.5 would break etc. So using java-config in launchers isn't only the case of ant, but pretty much anything gen-2. The best thing you can do is to write metadata for your external VM's and put it in /usr/share/java-config-2/vm - you can base it on some existing one. Then you can set the VM as your user VM and run stuff with it, or use GENTOO_VM env variable for temporary changes.
Creating my own metadata profiles in /usr/share/java-config-2/vm hasn't been a satsifactory experience. Briefly, I put things that I install myself such as Sun JVM's in /usr/local. If I create a metadata profile for such a JVM and select the JVM as the system JVM, java -version returns the errors: * Home for VM 'my-sun-j2sdk1.4.2_12' does not exist: /usr/lib/jvm/my-sun-j2sdk1.4.2_12 * Invalid System VM: my-sun-j2sdk1.4.2_12 What the hell is that? In the metadata I specified the correct location of the JVM home, and java-config ignores it and seems to require that all jvm's be installed in /usr/lib/jvm. Can you make java-config honor the information that's in the metadata? Why specify metadata if they are ignored?
You need a symlink in /usr/lib/jvm to point at the JAVA_HOME of your jdk/jre. ie ln -s /usr/local/myjdk /usr/lib/jvm/my-sun-j2sdk1.4.2_12
Created attachment 171084 [details, diff] optionally respect java_home instead of gentoo_vm in run-java-tool This introduces RESPECT_JAVA_HOME variable which, when set, makes every run-java-tool based launcher use JAVA_HOME instead of GENTOO_VM.
Created attachment 171085 [details, diff] ant launcher patch This makes ant just run "java" instead of its own detection, so that (in conjunction with patched java-config) if RESPECT_JAVA_HOME is set, the run-java-tool launcher will use JAVA_HOME. Additionally, tools.jar is taken from JAVA_HOME instead of java-config --tools.
Created attachment 171087 [details, diff] eclass patch unsetting RESPECT_JAVA_HOME for java building To prevent problems with building existing packages due to user's env, RESPECT_JAVA_HOME is set in the eclass. Packages that on the other hand need it (icedtea[6]) can set it afterwards.
*** Bug 217572 has been marked as a duplicate of this bug. ***
After discussion with betelgeuse, the change is to ant script only, not general run-java-tool and the variable is called ANT_RESPECT_JAVA_HOME which, if set and JAVA_HOME is set, it's not overriden. Commited in ant-core-1.7.1-r2