Question edited. I'm trying to run spring boot app in JNLP but after resolving all security issues I still get this error. It occurs during spring boot initialization at startup. It's related to spring boot lifecycle somehow and protection domain obviously, but I really do not know how to fix it. JAR runs flawlessly when running as standalone app with java -jar Test.jar
.
Exception from Java WebStart console:
Unable to determine code source archive from \\localhost:8080\jnlp\Test.jar
org.springframework.boot.loader.Launcher.createArchive(Launcher.java:151)
at org.springframework.boot.loader.PropertiesLauncher.<init>(PropertiesLauncher.java:149)
at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:607)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
The exception occurs in Launcher.java
(spring-boot-tools):
protected final Archive createArchive() throws Exception {
ProtectionDomain protectionDomain = getClass().getProtectionDomain();
CodeSource codeSource = protectionDomain.getCodeSource();
URI location = (codeSource == null ? null : codeSource.getLocation().toURI());
String path = (location == null ? null : location.getSchemeSpecificPart());
if (path == null) {
throw new IllegalStateException("Unable to determine code source archive");
}
File root = new File(path);
if (!root.exists()) {
throw new IllegalStateException(
"Unable to determine code source archive from " + root);
}
return (root.isDirectory() ? new ExplodedArchive(root)
: new JarFileArchive(root));
}
Spring boot is not able to get the absolute path for the executed spring boot jar - it passes just the URI in a format, in my case \localhost:8080\jnlp\Test.jar, normally the location
points to the absolute URI of the file. Therefore, spring boot is not able to initialize in Java WebStart.
My JNLP:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://localhost:8080/" href="Test.jnlp">
<information>
<vendor>TEST</vendor>
<homepage href="http://localhost:8080/" />
<description>Testing Testing</description>
</information>
<update check="timeout" policy="always"/>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.8+" />
<jar href="/jnlp/Test.jar" />
</resources>
<application-desc main-class="org.springframework.boot.loader.PropertiesLauncher" />
</jnlp>
Any hints how to push the absolute file path in Launcher.java
without fixing spring boot library?
UPDATE: I see that this could not be very easily resolved... Spring boot simply does not support running from non-file (or non-servlet) locations, as it works with custom classloader. Additionally the path
variable should be the same as the executed jar, so it is not possible to point boot to the newly downloaded file (the same jar actually). :(