亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Spring Boot 和 Java Web Start (JNLP) 時的異常

使用 Spring Boot 和 Java Web Start (JNLP) 時的異常

一只斗牛犬 2021-09-15 15:38:45
我正在使用 Spring Boot 構建應用程序。我將它打包為一個可執行的 jar。我想使用 Java Web Start 部署此應用程序。我寫了一個 JNLP 文件,但是當我嘗試運行它時,我讓他遵循 Exception :java.lang.IllegalStateException: Unable to determine code source archive from \\localhost\printpoc.jarat org.springframework.boot.loader.Launcher.createArchive(Launcher.java:126)at org.springframework.boot.loader.ExecutableArchiveLauncher.<init>(ExecutableArchiveLauncher.java:38)at org.springframework.boot.loader.JarLauncher.<init>(JarLauncher.java:35)at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)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)這是我的 JNLP 文件:<?xml version="1.0" encoding="utf-8"?><jnlp spec="1.0+" codebase="http://localhost/" href="printpoc.jnlp"><information>    <vendor>Me</vendor>    <homepage href="http://localhost/" />    <description>PrintPoc</description></information><security>    <all-permissions/></security><resources>    <j2se version="1.8+" />    <jar href="printpoc.jar" /></resources><application-desc main-class="org.springframework.boot.loader.JarLauncher" />我想嘗試一下,但布局 MODULE 不再存在。我嘗試了 ZIP、NONE 等,仍然沒有成功。這是我的 pom.xml :        <plugin>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-maven-plugin</artifactId>            <configuration>                <layout>JAR</layout>            </configuration>            <executions>                <execution>                    <goals>                        <goal>repackage</goal>                    </goals>                </execution>            </executions>        </plugin>你能幫我嗎?
查看完整描述

1 回答

?
蠱毒傳說

TA貢獻1895條經驗 獲得超3個贊

在我看來,這就像一個 Spring 錯誤。從來源:


ProtectionDomain protectionDomain = getClass().getProtectionDomain();

CodeSource codeSource = protectionDomain.getCodeSource();

URI location = (codeSource != null) ? codeSource.getLocation().toURI() : null;

String path = (location != null) ? location.getSchemeSpecificPart() : null;


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

}

問題是這一行:


String path = (location != null) ? location.getSchemeSpecificPart() : null;

從URI 文檔:


在最高級別,字符串形式的 URI 引用(以下簡稱“URI”)具有以下語法


[方案:]方案特定部分[#片段]


因此,在 URI 中http://localhost/printpoc.jnlp,特定于方案的部分是//localhost/printpoc.jnlp. 然后 Spring 嘗試將其視為文件名,這當然不存在,這就是為什么您會看到您所看到的異常。


Spring 代碼不正確。它錯誤地假設您可以從任何 URI 中創建文件名。只有file:URI 可以安全地轉換為文件名,這可以通過new File(location)或Paths.get(location)正確完成。


我不確定解決方案是什么。Spring Boot 啟動器似乎假設 .jar 始終是本地文件。我懷疑它是否可以與通過 HTTP 獲得的 .jar 文件一起使用。




查看完整回答
反對 回復 2021-09-15
  • 1 回答
  • 0 關注
  • 276 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號