Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#44806 - [java-runtime-common] JAVA_HOME environment variable not set

Attached to Project: Arch Linux
Opened by David Sankel (sankeld) - Friday, 01 May 2015, 19:09 GMT
Last edited by Guillaume ALAUX (galaux) - Saturday, 30 May 2015, 11:46 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Guillaume ALAUX (galaux)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No

Details

Description:
With the new java infrastructure, the environment variable 'JAVA_HOME' is not set. This causes problems with packages, such as CMake, which use this to discover the java location. The fix, which I think is general, would be to update the '/etc/profile.d/jre.sh' file to set 'JAVA_HOME' to '/usr/lib/jvm/java-default-runtime'.

Steps to reproduce:
Create a new 'CMakeLists.txt' file with the contents 'find_package( JRE required )' and note the error.
This task depends upon

Closed by  Guillaume ALAUX (galaux)
Saturday, 30 May 2015, 11:46 GMT
Reason for closing:  Not a bug
Comment by Guillaume ALAUX (galaux) - Saturday, 02 May 2015, 10:09 GMT
Could you please provide some details on how to reproduce this (just creating a text file will obviously not get me an error)? I suppose you are trying to build a particular project that uses cmake that fails to find JRE. Which project is this (and where could I get it)?
Comment by David Sankel (sankeld) - Saturday, 02 May 2015, 13:58 GMT
I'm a software developer using CMake to develop a package that uses JNI (a java/C layer). CMake uses the JAVA_HOME environment variable to discover the location of the java libraries.

There was a mistake in the initial "Steps to reproduce" section. Attached is a minimal 'CMakeLists.txt' that reproduces the error. Put it in an empty directory and type 'cmake .'.

CMake Error at /usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
Call Stack (most recent call first):
/usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:374 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.2/Modules/FindJNI.cmake:287 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:2 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/david/tmp/CMakeFiles/CMakeOutput.log".

If 'JAVA_HOME' is set in the environment, the error goes away: 'JAVA_HOME=/usr/lib/jvm/default cmake .'

-- Found JNI: /usr/lib64/jvm/default/jre/lib/amd64/libjawt.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/david/tmp
Comment by Guillaume ALAUX (galaux) - Saturday, 09 May 2015, 12:51 GMT
I see your point. I tend to consider setting this environment variable is a build configuration matter. As a developer I often find myself having to setup several variables such as SBT_OPTS or even _JAVA_OPTS, GRADLE_USER_HOME etc. If your project does not require any java libraries, `cmake` works OK without the need of JAVA_HOME. If your project does use java libs, then manually setting JAVA_HOME just like CFLAGS or any other build variable would be the way to go for me.
Does it sound right to you?
Comment by David Sankel (sankeld) - Saturday, 09 May 2015, 22:26 GMT
JAVA_HOME is a system configuration variable that holds the path to the system's currently enabled java installation. It is akin to having the 'java' executable in one's path.

CMake sensibly uses this information to figure out where to find the default Java development libraries. If someone wants to override these, the proper process is to use CMake variables; not to modify the JAVA_HOME environment variable as you indicated.

Other Arch users have had related problems that also also point to the fact that applications use JAVA_HOME to discover the location of the default java installation on a system. For java applications, using java in the path is just fine. For JNI applications and development tools like CMake, however, discovery of the installation path is necessary and this is done by using JAVA_HOME. All other distributions that I know of except recent versions of Arch set JAVA_HOME properly.

The other examples you cited (CFLAGS, etc.) are extension points and not system configuration variables as JAVA_HOME is.
Comment by Guillaume ALAUX (galaux) - Saturday, 09 May 2015, 23:29 GMT
I agree with you in that JAVA_HOME is a system configuration variable and I understand CMake uses it to find information to figure out the default Java dev libs. But I did not say you had to **modify** nor **override** it. I said you need to **set** it because it is not set by default on purpose.

About Archers having related problems due to applications using JAVA_HOME to discover the location of the default java installation on a system. Java end user applications doing so is a bad practice. End user application do not need to know where the JRE is installed. They just need to call `java` with the appropriate option. If the JRE package is cleanly installed, the `java` binary will be found and the application will start. Just like when you run `ls`. No matter where it is installed, you just run `ls` and your distro takes care of the rest whether `ls` is installed in `/usr/bin`, `/usr/local/bin`, `/bin` or wherever. The only explanation I can think of for Java applications trying to figure out where the JRE dates from the early days of JRE/JDK when they were not yet common on Linux distributions. People usually downloaded tarballs and extracted it here or there without always thinking about the PATH. So when you wanted to provide a Java end user app, you could not rely on PATH to find `java` – this is my own explanation, I might be totally wrong on this reason but it does not effect the fact that Java end user app do not need to know where the JRE is installed.
As for JNI and development tools like CMake I agree that discovery of the java home is done through the JAVA_HOME variable. I just think this is a system build environment variable that should be setup by hand if one needs it.

> All other distributions that I know of except recent versions of Arch set JAVA_HOME properly.
You might want to check that! http://pastebin.com/fbnRVtSu

Loading...