java jaxws-maven-plugin 解析相对于类位置的 WSDL 位置,为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14254838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 15:37:21  来源:igfitidea点击:

jaxws-maven-plugin resolving WSDL location relative to class location, why?

javamavenwsdljax-wsmaven-plugin

提问by Danubian Sailor

I'm using the jaxws-maven-pluginversion 2.1. I've found out very strange code generated for WSDL location from jar resources:

我正在使用该jaxws-maven-plugin版本2.1。我从 jar 资源中发现了为 WSDL 位置生成的非常奇怪的代码:

                <configuration>
                    <keep>true</keep>
                    <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                    <extension>true</extension>
                    <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
                    <packageName>my.package.gen</packageName>
                    <wsdlLocation>wsdl/*</wsdlLocation>
                    <wsdlFiles>
                        <wsdlFile>mywsdl.wsdl</wsdlFile>                            
                    </wsdlFiles>
                </configuration>

And the code generated is:

生成的代码是:

static {
    URL url = null;
    try {
        URL baseUrl;
        baseUrl = my.package.gen.My_Service.class.getResource(".");
        url = new URL(baseUrl, "wsdl/mywsdl.wsdl");
    } catch (MalformedURLException e) {
        logger.warning("Failed to create URL for the wsdl Location: 'wsdl/mywsdl.wsdl', retrying as a local file");
        logger.warning(e.getMessage());
    }
    MYSERVICE_WSDL_LOCATION = url; }

So the wsdl file is looked up in the directory (package) the generated class residents, and not in the main jar directory, as would be logical. And the WSDL can't be found.

因此 wsdl 文件是在生成的类居民的目录(包)中查找的,而不是在主 jar 目录中查找,这是合乎逻辑的。并且找不到 WSDL。

Is it a bug in jaxws-maven-plugin, or it is the error in my configuration?

是 中的错误jaxws-maven-plugin,还是我的配置中的错误?

采纳答案by Miklos Krivan

You should use jaxws-maven-plugin version 2.3 instead of 2.1 and the result will be as you would expected.

您应该使用 jaxws-maven-plugin 2.3 版而不是 2.1 版,结果将如您所愿。

The output of version 2.3 like this (if your wsdl folder is under src/main/resources):

2.3 版的输出是这样的(如果你的 wsdl 文件夹在 src/main/resources 下):

URL url = <Any>.class.getClassLoader().getResource("wsdl/anywsdl.wsdl");

回答by Samuel EUSTACHI

For the generation of

对于一代

url = new URL(baseUrl, "wsdl/mywsdl.wsdl");

This is the intended behavior, according to this,

这是预期的行为,根据this,

http://jax-ws-commons.java.net/jaxws-maven-plugin/wsimport-mojo.html#wsdlLocation

http://jax-ws-commons.java.net/jaxws-maven-plugin/wsimport-mojo.html#wsdlLocation

It depends on what you want to do.

这取决于你想做什么。

If what troubles you is

如果你有什么烦恼

My_Service.class.getResource(".");

My_Service.class.getResource(".");

You can get rid of the point (relative path) with something like :

您可以使用以下内容摆脱该点(相对路径):

<plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>1.5.0</version>
        <executions>
          <execution>
            <phase>process-sources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <file>target/generated-sources/wsimport/lu/hitec/webservices/pssu/${wsdl.app}/${interface.name}_Service.java</file>
          <replacements>
            <replacement>
              <token>_Service\.class\.getResource\("\."\)</token>
              <value>_Service\.class\.getResource\(""\)</value>
            </replacement>
          </replacements>
        </configuration>
      </plugin>