loicrouchon / findjava

finds the best JVM to run your java program
Apache License 2.0
4 stars 0 forks source link

Errors on Debian #1

Open ebourg opened 1 month ago

ebourg commented 1 month ago

Hi,

I'm trying to package findjava for Debian, it builds fine but I'm getting errors at runtime:

without arguments:

$ findjava
[ERROR] fail to call /usr/lib/jvm/java-11-openjdk-amd64/bin/java
        exit status 1

and with arguments:

$ findjava -min-java-version=11
[ERROR] fail to call /usr/lib/jvm/java-21-openjdk-amd64/bin/java
        exit status 1

The JVM path displayed in the error message changes on each invocation and seems randomly picked from /usr/lib/jvm/.

Here is the content of my /usr/lib/jvm/ directory:

$ ll /usr/lib/jvm/
total 32
lrwxrwxrwx 1 root   root     25 Jan 11  2023 default-java -> java-1.21.0-openjdk-amd64
lrwxrwxrwx 1 root   root     21 Oct 19  2022 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64
lrwxrwxrwx 1 root   root     21 Oct 19  2022 java-1.17.0-openjdk-amd64 -> java-17-openjdk-amd64
drwxr-xr-x 9 root   root   4096 Aug  5 19:25 java-11-openjdk-amd64
lrwxrwxrwx 1 root   root     21 Jan 26  2023 java-1.21.0-openjdk-amd64 -> java-21-openjdk-amd64
drwxr-xr-x 9 root   root   4096 Aug  5 19:25 java-17-openjdk-amd64
lrwxrwxrwx 1 root   root     20 Jan 29  2023 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64
drwxr-xr-x 9 root   root   4096 Aug  5 19:24 java-21-openjdk-amd64
drwxr-xr-x 8 ebourg ebourg 4096 Apr 10  2015 java-7-oracle-i386
drwxr-xr-x 7 root   root   4096 Jul 21 19:12 java-8-openjdk-amd64
drwxr-xr-x 3 root   root   4096 May 28  2018 java-9-openjdk-amd64
drwxr-xr-x 2 root   root   4096 Aug  5 19:24 openjdk-17
drwxr-xr-x 2 root   root   4096 Aug  5 19:24 openjdk-21
loicrouchon commented 1 month ago

Hi @ebourg and thanks for the report.

I managed to reproduce the issue and I'll be looking into it. I'll keep you posted here.

But apart from the problem you found, I'm happy to hear about the integration into debian. I would be happy to discuss with you about the best way to integrate findjava in the distribution. The idea is to give maximum control to maintainers about which JVMs are available for software packaged by the distribution itself.

loicrouchon commented 1 month ago

@ebourg , I created PR https://github.com/loicrouchon/findjava/pull/2 which should fix the issue if my assumptions are correct.

What I assumed, is that you built the software from the instructions in the README.md instead of relying on my very basic and probably broken in many ways ubuntu/debian packaging located in packaging/debian.

So let me know if the PR fixes your issue and if yes, I'll merge it.

ebourg commented 1 month ago

I may have messed with the paths actually. The binary is in /usr/bin/ and the class file in /usr/share/findjava/metadata-extractor/.

Here is the layout of the binary package:

$ dpkg -c /var/cache/pbuilder/result/findjava_0.3.2-1_amd64.deb
drwxr-xr-x root/root         0 2024-08-06 10:54 ./
drwxr-xr-x root/root         0 2024-08-06 10:54 ./etc/
-rw-r--r-- root/root       792 2024-08-06 10:54 ./etc/findjava
drwxr-xr-x root/root         0 2024-08-06 10:54 ./usr/
drwxr-xr-x root/root         0 2024-08-06 10:54 ./usr/bin/
-rwxr-xr-x root/root   2572888 2024-08-06 10:54 ./usr/bin/findjava
drwxr-xr-x root/root         0 2024-08-06 10:54 ./usr/share/
drwxr-xr-x root/root         0 2024-08-06 10:54 ./usr/share/doc/
drwxr-xr-x root/root         0 2024-08-06 10:54 ./usr/share/doc/findjava/
-rw-r--r-- root/root       158 2024-08-06 10:54 ./usr/share/doc/findjava/changelog.Debian.gz
-rw-r--r-- root/root       512 2024-08-06 10:54 ./usr/share/doc/findjava/copyright
drwxr-xr-x root/root         0 2024-08-06 10:54 ./usr/share/findjava/
drwxr-xr-x root/root         0 2024-08-06 10:54 ./usr/share/findjava/metadata-extractor/
-rw-r--r-- root/root      2317 2024-08-06 10:54 ./usr/share/findjava/metadata-extractor/JvmMetadataExtractor.class

I guess I just have to patch the value of platform.MetadataExtractorDir in linux.go?

loicrouchon commented 1 month ago

My apologies for the late response, I somehow missed the GitHub notification of your response.

I would prefer if you do not have to patch the source code. I'll check what are the options to provide a configurable build in the form of an environment variable you could pass when calling make.

When I tried to package it myself, I defined the following debian/rules I did put the binary in /usr/share/findjava/ so that the metadata extractor would be in the same directory

/usr/bin/findjava -> /usr/share/findjava/findjava
/usr/share/findjava/findjava
/usr/share/findjava/metadata-extractor/JvmMetadataExtractor.class

Do I assume correctly that you defined your own debian/rules file and that you called make in it? May I ask you to share it so that I have more insights on how you're trying to build.

ebourg commented 1 month ago

Do I assume correctly that you defined your own debian/rules file and that you called make in it?

Yes that's correct. lintian complained about the arch dependent binary in /usr/share/, so I've moved the binary directly under /usr/bin/. Also I've used a dh debian/findjava.install file instead of explicit install instructions in debian/rules.

The debian/rules file looks like this:

#!/usr/bin/make -f

GOCACHE=build/gocache

%:
        dh $@

override_dh_auto_build:
        mkdir -p "$(GOCACHE)"
        GOCACHE="$(GOCACHE)" GO_TAGS="-tags linux" GO_LD_FLAGS="-buildmode=pie" make build
        mkdir -p build/config
        cp packaging/debian/config.conf build/config/findjava

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
        mkdir -p "$(GOCACHE)"
        GOCACHE="$(GOCACHE)" GO_TAGS="-tags linux" make test
endif

and debian/findjava.install:

build/config/findjava                    /etc/
build/classes/JvmMetadataExtractor.class /usr/share/findjava/metadata-extractor/
build/go/findjava                        /usr/bin/
loicrouchon commented 1 month ago

I pushed some additional changes to branch bug/metadata-extractor-path defining a new build tag: debian which sets the expected location for the metadata extractor to /usr/share/findjava/metadata-extractor/.

You should be able to build using GO_TAGS="-tags debian" instead of GO_TAGS="-tags linux" without the need for patching any file on your side.

Let me know if that works and if the solution suits you.

loicrouchon commented 3 weeks ago

@ebourg I was not fully happy with the necessity to require a file for configuring variables.

So I worked a bit more on it and pushed new changes to https://github.com/loicrouchon/findjava/pull/2 so that you can also override things when building and even combine both approaches.

You now have a few build options:

Option 1

Use the pre-configured debian build tag:

GO_TAGS="-tags debian" make

Option 2

Use the pre-configured standalone_linux build tag and override remaining variables to be Debian compatible:

GO_TAGS="-tags standalone_linux" GO_LD_FLAGS="-X 'findjava/linker.MetadataExtractorDir=/usr/share/findjava/metadata-extractor'" make

Option 3

Override all the variables manually:

GO_LD_FLAGS="-X 'findjava/linker.ConfigDir=/etc/findjava/' -X 'findjava/linker.CacheDir=~/.cache/findjava/' -X 'findjava/linker.MetadataExtractorDir=/usr/share/findjava/metadata-extractor'" make

Checking the resulting binary

You can check the resulting binary with command:

$ ./build/dist/findjava --version -log-level=debug

findjava 0.3.2
[DEBUG] platform:
    program:                        /home/someuser/findjava/build/dist/findjava
    config directory:               /etc/findjava/
    cache directory:                /home/someuser/.cache/findjava/
    metadata extractor directory:   /usr/share/findjava/metadata-extractor

More details can be found in the README.md of #2