有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

web服务是连接。连接java。木卫一。URL有“+”时FileNotFoundException

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

JAR entry BOOT-INF/classes!/sam.wsdl not found in /Users/pp/git/Repo/build/libs/repo-1.1.0+1.jar

服务存储库:

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


共 (1) 个答案

  1. # 1 楼答案

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

    如果希望URL与文件名中的+匹配,则需要对+字符进行百分比转义;e、 g

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