【问题标题】:JarURLConnection.connect throwing java.io.FileNotFoundException when URL has "+"当 URL 有“+”时,JarURLConnection.connect 抛出 java.io.FileNotFoundException
【发布时间】:2018-11-02 19:37:23
【问题描述】:

JarURLConnection.connect 当 JAR 文件包含 + 字符时抛出 FileNotFoundException

在 /Users/pp/git/Repo/build/libs/repo-1.1.0+1.jar 中找不到 JAR 条目 BOOT-INF/classes!/sam.wsdl

服务存储库:

import java.io.IOException;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import org.springframework.core.io.ClassPathResource;

public class SampleService extends Service {

    public SampleService() throws IOException {
        super(new ClassPathResource("sam.wsdl", SampleService.class.getClassLoader()).getURL(), new QName("qname", "serv"));
    }
}

new ClassPathResource("sam.wsdl", SampleService.class.getClassLoader()).getURL() 解析为 URL 时,此代码运行良好

jar:file:/Users/pp/git/Repo/build/libs/repo-1.1.0.jar!/BOOT-INF/classes!/sam.wsdl

但是当我的 jar 包含 + 时会抛出 FNF 异常。

jar:file:/Users/pp/git/Repo/build/libs/repo-1.1.0+1.jar!/BOOT-INF/classes!/sam.wsdl

【问题讨论】:

    标签: java web-services spring-boot


    【解决方案1】:

    URL 中的+ 字符实际上是一个编码的空格 (ASCII SP / 0x20) 字符。

    如果您希望 URL 匹配文件名中带有 + 的文件,则需要对 + 字符进行百分号转义;例如

    jar:file:/Users/pp/git/Repo/build/libs/repo-1.1.0%2B1.jar!/BOOT-INF/classes!/sam.wsdl
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-03
      • 1970-01-01
      • 1970-01-01
      • 2017-09-07
      • 2021-10-11
      • 2019-01-24
      • 1970-01-01
      • 2021-11-23
      相关资源
      最近更新 更多