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

时间:2015-10-20 08:51:38

标签: java spring-boot jnlp

问题已编辑。我正在尝试在JNLP中运行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引导无法获取执行的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 library的情况下在Launcher.java中推送绝对文件路径的任何提示?

更新:我看到这个问题不容易解决... Spring启动根本不支持从非文件(或非servlet)位置运行,因为它适用于自定义类加载器。另外,path变量应该与执行的jar相同,因此无法将引导指向新下载的文件(实际上是相同的jar)。 :(

1 个答案:

答案 0 :(得分:0)

The solution was to add the MODULE layout for the plugin in the pom.xml file

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