无法使用Java WebStart在JNLP中启动Spring Boot

4

问题已编辑。 我正在尝试在JNLP中运行Spring Boot应用程序,但在解决了所有安全问题后,我仍然遇到此错误。它发生在Spring Boot启动期间的初始化过程中。它与Spring Boot生命周期和保护域有关,但我真的不知道该如何修复它。当使用java -jar Test.jar作为独立应用程序运行时,JAR文件运行得非常顺畅。

Java WebStart控制台的异常:

   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)

异常出现在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 无法获取执行的 Spring Boot JAR 的绝对路径 - 它只传递了 URI 格式的路径,例如 \localhost:8080\jnlp\Test.jar。通常,location 指向文件的绝对 URI,因此 Spring Boot 无法在 Java WebStart 中初始化。

我的 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>

有什么提示可以在不修复Spring Boot库的情况下推送Launcher.java的绝对文件路径?

更新: 我发现这可能很难解决...Spring Boot不支持从非文件(或非servlet)位置运行,因为它使用自定义类加载器。 此外,path 变量应与执行的jar文件相同,因此不可能将Boot指向新下载的文件(实际上是同一个jar文件)。 :(


你找到解决方案了吗? - Bhargav
不支持,并且Spring开发人员没有回复。 - Mejmo
那么Spring Boot不支持jnlp吗? - Bhargav
我的上一条回复已经说得很清楚了。 - Mejmo
有关这个问题的任何消息吗?我最终陷入了同样的境地... :( 还是不支持吗? - Pedro Silva
1个回答

0

解决方案是在pom.xml文件中为插件添加MODULE布局

<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <layout>MODULE</layout>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接