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