首页 文章

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

提问于
浏览
4

Question edited. 我和 spring 启动生命周期有点关系和保护域明显,但我真的不知道如何解决它 . 当使用 java -jar Test.jar 作为独立应用程序运行时,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引导无法获取执行的spring引导jar的绝对路径 - 它只传递一种格式的URI,在我的case \ localhost:8080 \ jnlp \ Test.jar中,通常 location 指向的绝对URI文件 . 因此,Spring Boot无法在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>

任何提示如何在不修复spring boot库的情况下推送 Launcher.java 中的绝对文件路径?

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

1 回答

相关问题