【问题标题】:Apache CXF WSDL2java pom.xml ConfigurationApache CXF WSDL2java pom.xml 配置
【发布时间】:2019-04-26 22:44:45
【问题描述】:

基本上我想要做的是我将在资源下创建 wsdl 文件夹,并将我的 wsdl 文件添加到其中。每次我在控制台上运行 mvn clean install 命令时,我对 cxf 插件的期望是从 wsdl 创建 java 文件。

但是,关于 apache cxf 文档,我应用了它所说的,但是当我运行 mvn generate-sources 时没有任何反应(如果你有的话,我将使用 mvn clean install 来创建 java 文件,而不是使用 mvn generate-sources 下一步任何建议也会很棒)。

这段代码有什么问题?

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.erkan</groupId>
<artifactId>wsClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>wsClient</name>
<url>http://maven.apache.org</url>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.codehaus.mojo/jaxws-maven-plugin -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-core</artifactId>
        <version>3.2.7</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.2.7</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/is.wsdl</wsdl>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${basedir}/src/main/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

【问题讨论】:

    标签: java apache maven cxf wsdl2java


    【解决方案1】:

    你应该在 plugins 中声明你的插件。

    链接:

    【讨论】:

    • 我从 pom.xml 中删除了 pluginManagement 标记,但它也不起作用。
    【解决方案2】:

    它适用于:

    docker run -ti -w /test -v $(pwd):/test maven:3-jdk-8 mvn generate-sources
    

    <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>com.erkan</groupId>
    <artifactId>wsClient</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <name>wsClient</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    
        <!-- https://mvnrepository.com/artifact/org.codehaus.mojo/jaxws-maven-plugin -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-core</artifactId>
            <version>3.2.7</version>
        </dependency>
    </dependencies>
    
    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-codegen-plugin</artifactId>
                    <version>3.2.7</version>
                    <executions>
                        <execution>
                            <id>generate-sources</id>
                            <phase>generate-sources</phase>
                            <configuration>
                                <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                                <wsdlOptions>
                                    <wsdlOption>
                                        <wsdl>${basedir}/src/main/resources/wsdl/is.wsdl</wsdl>
                                    </wsdlOption>
                                </wsdlOptions>
                            </configuration>
                            <goals>
                                <goal>wsdl2java</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.7</version>
                    <executions>
                        <execution>
                            <id>add-source</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>add-source</goal>
                            </goals>
                            <configuration>
                                <sources>
                                    <source>${basedir}/src/main/java</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
    </build>
    </project>
    

    【讨论】:

      【解决方案3】:

      由于某些原因,org.apache.cxf:cxf-codegen-plugin&lt;pluginManagement&gt;...&lt;/pluginManagement&gt; 中不起作用。

      在我之前的CXF项目中,我通常把它放在&lt;plugins&gt;&lt;/plugins&gt;里面。我已经尝试过使用您的pom.xml 并注意到cxf-codegen-plugin 已被忽略完成,即使它仍然出现在有效的 POM 中。

      您原来的pom.xml 存在另一个问题。在build-helper-maven-plugin 的目标add-source 中,&lt;source&gt;(将作为Java 代码添加)应该正是生成代码的文件夹(即cxf-codegen-plugin&lt;sourceRoot&gt;):

      <sources>
        <source>${project.build.directory}/generated/cxf</source>
      </sources>
      

      这是在我的测试项目中使用类似设置的完整pom.xml,您可以根据需要进行自定义。我刚刚添加了-verbose 选项,以便您可以在cxf-codegen-plugin 工作时看到一些信息。

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      
        <modelVersion>4.0.0</modelVersion>
      
        <groupId>io.github.htr3n</groupId>
        <artifactId>apache-cxf-demo</artifactId>
        <version>1.0-SNAPSHOT</version>
      
        <name>apache-cxf-demo</name>
      
        <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          <maven.compiler.source>1.7</maven.compiler.source>
          <maven.compiler.target>1.7</maven.compiler.target>
          <cxf.version>3.2.7</cxf.version>
        </properties>
      
        <dependencies>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
          </dependency>
          <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-core</artifactId>
            <version>${cxf.version}</version>
          </dependency>
        </dependencies>
        <build>
          <plugins>
            <plugin>
              <groupId>org.apache.cxf</groupId>
              <artifactId>cxf-codegen-plugin</artifactId>
              <version>3.2.4</version>
              <executions>
                <execution>
                  <id>generate-sources</id>
                  <phase>generate-sources</phase>
                  <configuration>
                    <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                    <wsdlOptions>
                      <wsdlOption>
                        <wsdl>${basedir}/src/main/resources/wsdl/is.wsdl</wsdl>
                        <defaultExcludesNamespace>true</defaultExcludesNamespace>
                        <extraargs>
                          <extraarg>-verbose</extraarg>
                        </extraargs>
                      </wsdlOption>
                   </wsdlOptions>
                  </configuration>
                  <goals>
                    <goal>wsdl2java</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
          <pluginManagement>
            <plugins>
              <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                  <encoding>UTF-8</encoding>
                  <source>${maven.compiler.source}</source>
                  <target>${maven.compiler.target}</target>
                </configuration>
              </plugin>
              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                  <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                      <goal>add-source</goal>
                    </goals>
                    <configuration>
                      <sources>
                        <source>${project.build.directory}/generated/cxf</source>
                      </sources>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
            </plugins>
          </pluginManagement>
        </build>
      </project>
      

      您只需要运行mvn clean compile,因为compile 包括generate-sources

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-03-22
        • 1970-01-01
        • 2011-01-13
        • 1970-01-01
        • 2021-04-26
        • 1970-01-01
        • 2012-10-03
        • 1970-01-01
        相关资源
        最近更新 更多