4

I've modularized my Java 9 application after much pain, but now that things seem to be working, I want to create a native launcher for my application.

I used jlink to do it.

Here's the Gradle task I used to invoked jlink:

task jlink(type: Exec) {
    dependsOn(':rawhttp-core:jar', ':java9-nullable:jar')
    def javaHome = System.properties['java.home']
    def libs = configurations.runtime.collect { it.absolutePath }
    libs += "$javaHome/jmods"
    libs += jar.archivePath.absolutePath

    commandLine 'jlink', '-p', libs.join(File.pathSeparator),
            '--add-modules', 'com.athaydes.rawhttp.cli',
            '--launcher', 'rawhttp=com.athaydes.rawhttp.cli/com.athaydes.rawhttp.cli.Main',
            '--strip-debug', '--compress=2',
            '--no-header-files', '--no-man-pages',
            '--output', 'dist'

    doFirst {
        delete file('dist')
    }
}

This works and I can launch the Java application using the launcher:

dist/bin/rawhttp

But when I add a symlink to it in Linux, it won't work...

Here's how I add the link:

ln -s $(pwd)/rawhttp-cli/dist/bin/rawhttp /usr/local/bin/rawhttp

And when I ran rawhttp I get this error:

/usr/local/bin/rawhttp: 4: /usr/local/bin/rawhttp: /usr/local/bin/java: not found

So, it looks like the generated launcher doesn't know how to refer to other files relative to itself! In my opinion, this is a basic mistake by whoever wrote the code for the launcher!

Here's the generated launcher file:

#!/bin/sh
JLINK_VM_OPTIONS=
DIR=`dirname $0`
$DIR/java $JLINK_VM_OPTIONS -m com.athaydes.rawhttp.cli/com.athaydes.rawhttp.cli.Main $@

Does anyone know a workaround for this that does not involve manually fixing the launcher that Java's jlink is generating?

Java version I am using: 9.0.4+11 OS: Ubuntu

Renato
  • 12,940
  • 3
  • 54
  • 85
  • If you don't want to do it manually then maybe write a script that fixes it in an automated fashion and include that in your build process? – the8472 Mar 11 '18 at 19:33
  • 1
    I will end up doing that, of course... just created this ticket to raise awareness of this issue (I dion't have time to create a bug issue in Oracle's ridiculous bug tracker) and maybe learn if someone finds a better way, who knows. – Renato Mar 11 '18 at 20:06
  • Might be useful to link the bug number here in case anyone else stumbles over the issue. – the8472 Mar 11 '18 at 22:16
  • Ultimately the generated scripts should be replaced by a native launcher, tracked here: https://bugs.openjdk.java.net/browse/JDK-8182555 – Alan Bateman Mar 12 '18 at 07:23
  • 1
    The generated launcher is supposed to gets its own location from $0, yes? It is expecting both itself and java.exe to be in the same directory. Are they? – Phil Freihofner Aug 20 '18 at 03:27

0 Answers0