java 多个WSDL URL使用maven-jaxb 2-plugin生成源代码

vmdwslir  于 2023-05-27  发布在  Java
关注(0)|答案(2)|浏览(106)
<!-- tag::wsdl[] -->
<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.12.3</version>
    <executions>
        <execution>
            <id>firstrun</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaLanguage>WSDL</schemaLanguage>
                <generatePackage>my.package.osb.services.wsdl1</generatePackage>
                <schemas>
                    <schema>
                        <url>http://x.x.x.x:8002/wsdl1?wsdl</url>
                    </schema>
                </schemas>
            </configuration>
        </execution>
        <execution>
            <id>secondrun</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
            <schemaLanguage>WSDL</schemaLanguage>
            <generatePackage>my.package.osb.services.wsdl2</generatePackage>
            <schemas>
                <schema>
                    <url>http://x.x.x.x:8002/wsdl2?wsdl</url>
                </schema>
            </schemas>
            </configuration>
        </execution>
    </executions>
</plugin>
<!-- end::wsdl[] -->

我的理解是,上面应该在两个不同的包中生成两个URL中描述的POJO。
我不明白为什么它不工作。我在mvn jaxb2:generate之后得到的错误是No schemas to compile. Skipping XJC execution.
能否提供一个完整的解决方案,说明如何正确地使用WSDL URL来完成此操作?

wz3gfoph

wz3gfoph1#

如果你运行mvn jaxb2:generate,maven在执行中不会使用configuration
您已经声明了一个phase,您的执行应该绑定在这个phase上,所以只需运行mvn generate-sources即可。
https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag 说:

注意:<executions>标签内的配置与<executions>标签外的配置不同,不能直接通过命令行调用。相反,它们仅在它们绑定到的生命周期阶段被调用时才被应用。或者,如果您将配置部分移动到执行部分之外,它将全局应用于插件的所有调用。

vc6uscn9

vc6uscn92#

在这个结构中,将插件加倍对我有效:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.14.0</version>
    <executions>
      <execution>
        <goals>
          <goal>generate</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <schemaLanguage>WSDL</schemaLanguage>
      <generatePackage>asd1.wsdl</generatePackage>
      <schemas>
        <schema>
          <url>http://..1?WSDL</url>
        </schema>
      </schemas>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.14.0</version>
    <executions>
      <execution>
        <goals>
          <goal>generate</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <schemaLanguage>WSDL</schemaLanguage>
      <generatePackage>asd.wsdl</generatePackage>
      <schemas>
        <schema>
          <url> http://...?WSDL</url>
        </schema>
      </schemas>
    </configuration>
  </plugin>

相关问题