【问题标题】:Automatic WSDL Java Stub generation in Eclipse Workspace using Apache CXF and CXF Maven Plugin使用 Apache CXF 和 CXF Maven 插件在 Eclipse Workspace 中自动生成 WSDL Java Stub
【发布时间】:2015-11-13 19:01:58
【问题描述】:

我正在使用 Apache CXF 2.x、Eclipse Luna 64 位、Maven 3.x

我有一个具有 WSDL 的 Web 服务生产者应用程序,我希望应用程序中的存根从 WSDL 动态生成。

我已经安装了 Maven Lifecycle Dependency 并安装了两个 M2E WTP 连接器。在 Eclipse Project -> Properties -> Maven -> Lifecycle Mapping 中,我看到 cxf-codegen-plugin:wsdl2java 并且它表明它已正确附加到 generate-sources 生命周期阶段。

当我手动运行mvn install 时,存根会自动生成,一切正常。

但是如果我清理 maven 项目并将其加载到 eclipse 中,eclipse 不会自动生成存根。我在 Eclipse 工作区中看到 Java 缺少类错误,显示 gen 没有发生。

我错过了什么步骤?

这是我正在使用的 POM。

<?xml version="1.0" encoding="UTF-8"?>
<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.test</groupId>
    <artifactId>testWeb</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>testWeb</name>

    <properties>
        <cxf.version>2.1.3</cxf.version>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
        <spring.version>3.2.2.RELEASE</spring.version>
    </properties>

    <repositories>
        <repository>
            <id>snapshots</id>
            <name>ILP Snapshot Repository</name>
            <url>http://dhud001.test.com:8675/maven_snapshot/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>       
        <repository>
            <id>eclipse</id>
            <name>Eclipse</name>
            <url>https://repo.eclipse.org/content/repositories/releases/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <name>Maven Plugin Repository</name>
            <url>http://repo1.maven.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf</artifactId>
            <version>${cxf.version}</version>
        </dependency>        
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/gen/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <useCompileClasspath>true</useCompileClasspath> <!-- if you don't use this, the soapui test bundle will cause classloading issues with this plugin. -->
                            <sourceRoot>${project.basedir}/src/gen/java</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${project.basedir}/src/main/webapp/wsdl/TestService.wsdl</wsdl>
                                    <wsdlLocation>classpath:wsdl/TestService.wsdl</wsdlLocation>
                                    <extraargs>
                                        <extraarg>-verbose</extraarg>
                                        <extraarg>-all</extraarg>
                                                                                </extraargs>
                                </wsdlOption>
                            </wsdlOptions>                            
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>               
            </plugin>
        </plugins>
    </build>
</project>

我能够安装 Build helper maven 连接器,并且还尝试安装 https://code.google.com/a/eclipselabs.org/p/m2e-cxf-codegen-connector/。但源继续不生成。

可以重现问题的示例eclipse项目在这里:https://www.dropbox.com/s/vlo0ghbmkplu7au/service.zip?dl=0

【问题讨论】:

  • 您在 cxf-users 邮件列表中询问了吗?
  • 我会调查一下,注册和东西很棘手。
  • 您可能需要设置一些未记录的标志,例如-Dm2e.cxf.actually.work.this.time=true 或其他东西。
  • 谢谢你提醒我为什么改用 IntelliJ,够用的 JAX-WS RI codegen,不够用的 Axis2,只做依赖和实际的 compile/jar/war/ejb/ear使用 Maven 的东西。
  • 这绝对不是什么标志。我认为这是因为新版本的 jar 与它的旧工作方式相冲突。也许 MyEclipse 正确地解决了这个问题?

标签: eclipse cxf


【解决方案1】:

我不确定您在什么情况下期望什么,但 cxf m2e 插件的生命周期映射似乎存在问题,因为清理机制没有清理适合该插件的目标文件夹。

所以,只需手动删除目标文件夹(或至少删除“cxf-codegen-plugin-markers”子文件夹),然后运行构建。这应该会在需要的地方生成 java 文件。

您还可以通过“运行”或“调试”上下文菜单项执行 Maven 目标。 Maven 确实删除了整个“目标”文件夹。因此,从上下文运行菜单(或从 Maven 运行配置)运行干净和安装也可以满足您的需要。

请注意,命令行 maven 不喜欢您的“cxf”依赖项,而且它似乎也不需要。我必须删除它才能让它工作。

最后一件事,cxf 插件在 eclipse 构建后也不会刷新项目,这需要查看构建中生成的内容。因此,在构建之后需要在 eclipse 项目上快速按 F5。

【讨论】:

  • 嗨托尼。感谢您花时间回答。我已经能够从 Eclipse 运行 mvn clean/install 并创建存根。那从来都不是问题。问题是,当我对 WSDL 进行更改时,我希望 Eclipse 能够自动检测到该更改,在 src/gen/java 文件夹中生成存根,然后您就会在工作区中看到更改。这没有发生。我每次都必须手动运行 mvn install 才能对存根进行更新。非常烦人且耗时,因为我们更改了 WSDL 很多
  • 好的,尼古拉斯。我从你的主要问题中得到了不同的信息。看起来 cxf m2e 连接器的生命周期映射不太正确。您可以通过将生命周期映射元数据部分的空执行元素(仅在您的示例项目中,而不是问题中给出的 pom 中)替换为:&lt;execute&gt; &lt;runOnIncremental&gt;true&lt;/runOnIncremental&gt; &lt;/execute&gt; 原则上,这应该运行增量构建的目标。
  • 为您的帮助奖励了您 100+ 赏金。再次感谢。请参阅我最终在下面的完全事故中找到的答案。真是太幸运了,我想通了
  • 谢谢,尼古拉斯。我没有花很多时间在这上面,但是在将 runOnIncremental 属性添加到 pom 之后,确实设法让它在 WSDL 更改上运行一次,尽管它似乎没有第二次运行。可能需要进行更多调查才能准确找出有效的方法。
【解决方案2】:

为了让“更新 Maven 项目”触发 cxf 存根从 Eclipse 重建,您需要打开 target 文件夹并删除 target/*。然后点击alt + f5 + enter,你的存根就会刷新。

出于某种原因,手动清理目标文件夹内容会触发 maven 的 cxf 构建以生成存根。更改 WSDL/删除生成的源 src 文件夹的内容有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-06
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    相关资源
    最近更新 更多