FS#42346 - [java-common] add support for version specific Java env

Attached to Project: Arch Linux
Opened by Guillaume ALAUX (galaux) - Sunday, 12 October 2014, 20:16 GMT
Last edited by freswa (frederik) - Tuesday, 24 March 2020, 19:01 GMT
Task Type Feature Request
Category Packages: Extra
Status Closed
Assigned To Guillaume ALAUX (galaux)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:

Add link such as

/usr/lib/jvm/default-runtime-7
/usr/lib/jvm/default-7
/usr/lib/jvm/default-runtime-8
/usr/lib/jvm/default-8

These could be changed with "archlinux-java set -7 jre-7-openjdk" and "archlinux-java set -8 jre-8-openjdk"

Original request: https://lists.archlinux.org/pipermail/arch-general/2014-October/037465.html
This task depends upon

Closed by  freswa (frederik)
Tuesday, 24 March 2020, 19:01 GMT
Reason for closing:  Implemented
Additional comments about closing:  package archlinux-java
Comment by Matthias Lisin (matthias.lisin) - Sunday, 19 January 2020, 11:58 GMT
Hey galaux, I've recently had the same situation but now found this issue from 2014, hope you don't mind reviving it.
Had a conversation with eli a while ago on IRC where we came up with another approach (though admittedly gave it only 10 minutes of though).

(excuse my pseudo-markdown)

**Problem**
Packages wants to provide Java application which works best with Java 8 so he specifies `java-runtime=8` as dependency. However the end-user might not use another version as default (7, 10, 11 or 13) so simply running the application by `java -cp "[libs]" org.my.App` won't work.

If one resorts to using a fixed path (e.g. `PATH="/usr/lib/jvm/java-8-openjdk/bin:${PATH}"`) then non-OpenJDK users are forced to install the openjdk runtime.
The Oracle Java is quiet popular among Arch users according to AUR, so it shouldn't be ignored (imo).

**Requirement**
Packagers should be able to specify `java-runtime=8` and reliably run the application with version 8, regardless of the implementation/brand/vendor (however it's called).

**My proposal**
Give users the ability to get the runtime path for a specific version.

# returns first match (java-13-*), since the paths are sorted by the script, the result is always the same.
$ archlinux-java get-path 13
Output: /usr/lib/jvm/java-13-jdk

# however if default-runtime is set to `java-13-openjdk`, it is returned instead
$ archlinux-java get-path 13
Output: /usr/lib/jvm/java-13-openjdk

# The user proceeds with running the bin/java under that path or prepending the PATH variable in his wrapper script
# (in theory) get-path should never fail if the dependencies in PKGBUILD are properly specified
```bash
#!/bin/bash
JRE13=$(archlinux-java get-path 13)
PATH="${JRE13}/bin:${PATH}"
java -cp "/opt/myapp/app.jar" org.my.App
```

My implementation (+tests): https://codeberg.org/ml/java-common/src/branch/master/trunk
(same structure as the packages/java-commons branch in archlinux git repo in case you want diff/apply.

Feedback of any kind is appreciated.

**Conclusion**
I agree that returning the first match in case it's not the default-runtime is somewhat unintuitive. I also really like your approach and would provide the implementation if you want.
All I really want is to solve this issue.

Loading...