有 Java 编程相关的问题?

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

java如何引用一个。src/main/resources文件夹中的wsdl文件?

我有一个soapweb服务,我用wsimport.wsdl提取它

现在,当打开生成的文件时,我需要删除file://引用

我将WSDL移动到src/main/resources/Services/RecherchePoint-v2.0.wsdl

但现在,我有几个参考资料不知道如何更新:

@WebServiceClient(name = "RecherchePointV2.0", targetNamespace = "http://www.enedis.fr/sge/b2b/services", wsdlLocation = "file:/home/ubuntu/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl")

...

static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("file:/home/ubuntu/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        RECHERCHEPOINTV20_WSDL_LOCATION = url;
        RECHERCHEPOINTV20_EXCEPTION = e;
    }

我试着改变:

file:/home/ubuntu/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl"

../../../resources/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl"

但它不起作用

你知道怎么改吗


共 (2) 个答案

  1. # 1 楼答案

    您可以将该文件放在参考资料中,并且可以使用类加载器来获取该文件

    ClassLoader classLoader = getClass().getClassLoader();  
    File file = new File(classLoader.getResource("RecherchePoint-v2.0.wsdl").getFile());
    
  2. # 2 楼答案

    你可以使用org。springframework。果心木卫一。类路径资源

    /**
     * {@link Resource} implementation for class path resources. Uses either a
     * given {@link ClassLoader} or a given {@link Class} for loading resources.
     *
     * <p>Supports resolution as {@code java.io.File} if the class path
     * resource resides in the file system, but not for resources in a JAR.
     * Always supports resolution as URL.
     *
     */
    
    new ClassPathResource("Services/RecherchePoint-v2.0.wsdl")
    

    Here一些解释