¿Cuál es el objetivo correcto para la variable JAVA HOME envrionment para una distribución Linux OpenJDK basada en Debian?


En Windows, JAVA_HOME debe apuntar a la carpeta de instalación JDK (de modo que JAVA_HOME/bin contiene todos los ejecutables y JAVA_HOME/libs contiene todas las bibliotecas predeterminadas jar).

Si descargo el paquete JDK de Sun y lo instalo en Linux, es el mismo procedimiento.

Sin embargo, necesito usar el paquete OpenJDK predeterminado de Kubuntu. El problema es que todos los ejecutables se colocan en /usr/bin. Pero los frascos se colocan en /usr/share/java. Dado que no están bajo la misma carpeta JAVA_HOME estoy teniendo problemas con Grails y tal vez habrá problemas con otras aplicaciones que esperan la estructura estándar de Java.

  1. Si utilizo:

    JAVA_HOME=/usr
    

    Todas las aplicaciones y scripts que quieran usar cualquier ejecutable Java pueden usar el procedimiento estándar call $JAVA_HOME/bin/executable. Sin embargo, dado que los frascos están en un lugar diferente, no siempre se encuentran (ejemplo: en griales estoy recibiendo ClassDefNotFound para native2ascii).

  2. Por otro lado, si utilizo:

    JAVA_HOME=/usr/share/java
    

    Ninguno de los ejecutables Java (java, javac, etc.) se puede encontrar.

Entonces, ¿cuál es la forma correcta de manejar la variable JAVA_HOME en un Linux basado en Debian?

Gracias por su ayuda, Luis

Author: BuZZ-dEE, 2009-03-19

13 answers

Lo que finalmente funcionó para mí (Grails ahora funciona sin problemas) está haciendo casi como Steve B. ha señalado:

JAVA_HOME=/usr/lib/jvm/default-java

De esta manera, si el usuario cambia el JDK predeterminado para el sistema, JAVA_HOME todavía funciona.

default-java es un enlace simbólico a la JVM actual.

 86
Author: Luis Soeiro,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-14 11:50:27

Si utiliza alternativas, puede establecer el JAVA_HOME basado en el java enlazado simbólicamente de la siguiente manera:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
 53
Author: bbaassssiiee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-07 08:24:59

La instalación estándar de Ubuntu parece poner las diversas versiones de Java en /usr/lib/jvm. El javac, java que encuentre en su ruta se enlazará con este enlace.

No hay problema con la instalación de su propia versión de Java en cualquier lugar que desee, siempre y cuando establezca la variable de entorno JAVA_HOME y asegúrese de tener el nuevo Java bin en su ruta.

Una forma sencilla de hacerlo es hacer que Java home exista como un softlink, de modo que si quieres actualizar o cambiar versiones solo tienes que cambiar el directorio al que apunta-por ejemplo:

/usr/bin/java --> /opt/jdk/bin/java,

/opt/jdk --> /opt/jdk1.6.011
 5
Author: Steve B.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-14 12:32:42

Normalmente no tengo ninguna variable de entorno JAVA_HOME. Java puede configurarlo por sí mismo. Dentro de java java.la propiedad home system debe estar disponible.

 0
Author: iny,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-03-19 19:28:10

Intente establecer la variable JAVA_LIB también.

 0
Author: Cantillon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-03-19 20:01:05

Por lo que recuerdo, usé el script update-java-alternatives en lugar del script update-alternatives. Y estableció el JAVA_HOME para mí correctamente.

 0
Author: Tobias Schulte,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-03-20 10:51:49

Si tiene problemas con los archivos JAR que no se encuentran, también me aseguraría de que su CLASSPATH esté configurado para incluir la ubicación de esos archivos. Sin embargo, encuentro que el CLASSPATH a menudo debe configurarse de manera diferente para diferentes programas y, a menudo, termina siendo algo que debe configurarse de manera única para programas individuales.

 0
Author: MVang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-03-14 15:53:02

Respuesta actualizada que resolverá su problema y también solo un buen cómo general para instalar Oracle Java 7 en Ubuntu se puede encontrar aquí: http://www.wikihow.com/Install-Oracle-Java-on-Ubuntu-Linux

 0
Author: Jack,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-12 06:50:41

He descubierto problemas similares con los paquetes openjdk-6-jre y openjdk-6-jre-headless en Ubuntu.

Mi problema se resolvió purgando los paquetes openjdk-6-jre y openjdk-6-jre-headless y reinstalando. Las alternativas solo se actualizan en una nueva instalación de los paquetes openjdk-6-jre y openjdk-6-jre-headless.

A continuación se muestra una muestra de la instalación después de la purga:

aptitude purge openjdk-6-jre openjdk-6-jre-headless # to ensure no configuration exists
aptitude install --without-recommends openjdk-6-jre # Installing without some extras
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
  ca-certificates-java{a} java-common{a} libavahi-client3{a} libavahi-common-data{a} libavahi-common3{a} libcups2{a} libflac8{a} libgif4{a} libnspr4-0d{a} libnss3-1d{a} libogg0{a} libpulse0{a} libsndfile1{a} libvorbis0a{a} libvorbisenc2{a} libxi6{a} libxtst6{a}
  openjdk-6-jre openjdk-6-jre-headless{a} openjdk-6-jre-lib{a} tzdata-java{a}
The following packages are RECOMMENDED but will NOT be installed:
  icedtea-6-jre-cacao icedtea-netx ttf-dejavu-extra
0 packages upgraded, 21 newly installed, 0 to remove and 119 not upgraded.
Need to get 0B/34.5MB of archives. After unpacking 97.6MB will be used.
Do you want to continue? [Y/n/?]
Writing extended state information... Done
Selecting previously deselected package openjdk-6-jre-lib.
(Reading database ... 62267 files and directories currently installed.)
Unpacking openjdk-6-jre-lib (from .../openjdk-6-jre-lib_6b24-1.11.5-0ubuntu1~10.04.2_all.deb) ...
...
Processing triggers for man-db ...
Setting up tzdata-java (2012e-0ubuntu0.10.04) ...
...
Setting up openjdk-6-jre-headless (6b24-1.11.5-0ubuntu1~10.04.2) ...
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/java to provide /usr/bin/java (java) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/keytool to provide /usr/bin/keytool (keytool) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/pack200 to provide /usr/bin/pack200 (pack200) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/rmid to provide /usr/bin/rmid (rmid) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/rmiregistry to provide /usr/bin/rmiregistry (rmiregistry) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/unpack200 to provide /usr/bin/unpack200 (unpack200) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/orbd to provide /usr/bin/orbd (orbd) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/servertool to provide /usr/bin/servertool (servertool) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/tnameserv to provide /usr/bin/tnameserv (tnameserv) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/lib/jexec to provide /usr/bin/jexec (jexec) in auto mode.
Setting up openjdk-6-jre (6b24-1.11.5-0ubuntu1~10.04.2) ...
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/policytool to provide /usr/bin/policytool (policytool) in auto mode.
...

Puede ver más arriba que update-alternatives se ejecuta para configurar enlaces para los diversos Java binario.

Después de esta instalación, también hay enlaces en /usr/bin, enlaces en /etc/alternatives y archivos para cada binario en /var/lib/dpkg/alternatives.

ls -l /usr/bin/java /etc/alternatives/java /var/lib/dpkg/alternatives/java
lrwxrwxrwx 1 root root  40 2013-01-16 14:44 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk/jre/bin/java
lrwxrwxrwx 1 root root  22 2013-01-16 14:44 /usr/bin/java -> /etc/alternatives/java
-rw-r--r-- 1 root root 158 2013-01-16 14:44 /var/lib/dpkg/alternatives/java

Vamos a contast esto con la instalación sin purgar.

aptitude remove openjdk-6-jre
aptitude install --without-recommends openjdk-6-jre
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
  ca-certificates-java{a} java-common{a} libavahi-client3{a} libavahi-common-data{a} libavahi-common3{a} libcups2{a} libflac8{a} libgif4{a} libnspr4-0d{a} libnss3-1d{a} libogg0{a} libpulse0{a} libsndfile1{a} libvorbis0a{a} libvorbisenc2{a} libxi6{a} libxtst6{a}
  openjdk-6-jre openjdk-6-jre-headless{a} openjdk-6-jre-lib{a} tzdata-java{a}
The following packages are RECOMMENDED but will NOT be installed:
  icedtea-6-jre-cacao icedtea-netx ttf-dejavu-extra
0 packages upgraded, 21 newly installed, 0 to remove and 119 not upgraded.
Need to get 0B/34.5MB of archives. After unpacking 97.6MB will be used.
Do you want to continue? [Y/n/?]
Writing extended state information... Done
Selecting previously deselected package openjdk-6-jre-lib.
(Reading database ... 62293 files and directories currently installed.)
Unpacking openjdk-6-jre-lib (from .../openjdk-6-jre-lib_6b24-1.11.5-0ubuntu1~10.04.2_all.deb) ...
...
Processing triggers for man-db ...
...
Setting up openjdk-6-jre-headless (6b24-1.11.5-0ubuntu1~10.04.2) ...

Setting up openjdk-6-jre (6b24-1.11.5-0ubuntu1~10.04.2) ...
...

Como ves, update-alternatives no se activa.

Después de esta instalación, no hay archivos para los binarios Java en /var/lib/dpkg/alternatives, no hay enlaces en /etc/alternatives, y no hay enlaces en /usr/bin.

La eliminación de los archivos en /var/lib/dpkg/alternatives también rompe update-java-alternatives.

 0
Author: Saturn Junction,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-16 18:54:45

Ubuntu 12.04 esto funciona...

JAVA_HOME= / usr/lib/jvm/java-6-openjdk-i386 / jre

 0
Author: Alex,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-06 23:51:56

Como una actualización para el usuario de fedora, alternatives establece el directorio java actual a /usr / java / default

Así que tienes que establecer tu JAVA_HOME en / usr / java / default para tener siempre alternativas curent selection en tu classpath

HTH !

 0
Author: Greg Henry,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-06 21:16:22

Mi objetivo correcto siempre ha sido descargarlo desde Sun e instalarlo de esa manera. Entonces sabes exactamente en qué directorio va todo.

Pero si prefiere seguir con la extraña forma en que Debian lo instala, mi mejor conjetura sería el directorio padre justo arriba donde se encuentran los binarios java y javac.

(ya que cuando lo especificas en tu ruta es JAV JAVA_HOME / bin) (Así que en su caso sería ... JAV JAVA_HOME / share y JAV JAVA_HOME serían / usr ?)

Eh, eso no suena bien...

Estoy interesado en escuchar la respuesta a esto también!

 -1
Author: leeand00,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-03-19 19:26:36

Por favor vea lo que hace el comando update-alternatives (tiene un buen hombre...).

En breve - lo que sucede cuando se tiene java-sun-1.4 y java-opensouce-1.0 ... que uno toma "java"? Es debian "/usr/bin/java" es el vínculo simbólico y "/usr/bin/java-sun-1.4" es una alternativa a "/usr/bin/java"

Editar: Como dijo Richard, update-alternatives no es suficiente. Realmente necesitas usar update-java-alternatives. Más información en:

Https://help.ubuntu.com/community/Java

 -1
Author: elcuco,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-08-11 05:02:57