【问题标题】:Using xjc's -enableIntrospection with jaxws-maven-plugin将 xjc 的 -enableIntrospection 与 jaxws-maven-plugin 一起使用
【发布时间】:2011-01-03 17:56:19
【问题描述】:

遇到http://java.net/jira/browse/JAXB-131,我们正在尝试采用其 cmets 中提供的解决方法,即在 xjc 的命令行上提供 -enableIntrospection。

但是,当我这样做时:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>1.12</version>
            <executions>
                <execution>
                    <id>allservice</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <xjcArgs><xjcArg>-enableIntrospection</xjcArg></xjcArgs>
                        <extension>true</extension>
                        <wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
                        <bindingDirectory>src/main/resources/bindings</bindingDirectory>
                        <target>2.0</target>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>javax.jws</groupId>
                    <artifactId>jsr181-api</artifactId>
                    <version>1.0</version>
                </dependency>
            </dependencies>
        </plugin>

maven 构建失败:

[DEBUG] The binding Directory is C:\Source\workspace\TheProject\src\main\resources\bindings
[DEBUG] jaxws:wsimport args: [-s, C:\Source\workspace\TheProject\target\jaxws\wsimport\java, -d, C:\Source\workspace\TheProject\target\classes, -target, 2.0, -extension, -Xnocompile, -B-enableIntrospection, -b, C:\Source\workspace\TheProject\src\main\resources\bindings\servicebindings.xml]
[INFO] jaxws:wsimport args: [-s, C:\Source\workspace\TheProject\target\jaxws\wsimport\java, -d, C:\Source\workspace\TheProject\target\classes, -target, 2.0, -extension, -Xnocompile, -B-enableIntrospection, -b, C:\Source\workspace\TheProject\src\main\resources\bindings\servicebindings.xml, C:\Source\workspace\TheProject\src\main\webapp\WEB-INF\wsdl\CaseService.wsdl]
no such JAXB option: -enableIntrospection

如何将 xjc 的 -enableIntrospection 与 jaxws-maven-plugin 一起使用?如果我不能,有什么替代方法可以自定义 jaxws 的代码生成,以便将 Boolean 属性的 getter 称为 getFoo()(正确)而不是 isFoo()(这违反了 Java Beans 规范)。

【问题讨论】:

    标签: java jaxb maven jax-ws


    【解决方案1】:

    将布尔值的 getter 添加到 JAX-WS 生成的工件中,而不是使用 enableIntrospection 选项和 Java 认可的覆盖机制。

    只有 JAX-WS RI 2.1.13 支持选项 enableIntrospection。但是 JavaSE6 1.6.0_65 附带 JAVA-WS RI 2.1.6。解决此问题的一种方法是使用 Java 认可的覆盖机制,将 jaxws-api.jar 和 jaxb-api.jar 复制到 JRE/JDK 认可的目录中。

    另一种方法是不使用 enableIntrospection 选项,而是将布尔值的 getter 添加到 JAX-WS 生成的工件中。这些 getter 可以通过 replacer maven 插件添加。

    Maven替换插件添加get方法:

    <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>1.5.2</version>
        <executions>
            <execution>
                <phase>process-resources</phase>
                <goals>
                    <goal>replace</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <basedir>${project.basedir}</basedir>
            <includes>
                <include>src/main/java/lu/etat/cie/rn/rpp/ws/**/*.java</include>
            </includes>
            <token>public Boolean is(.*)\(\)(\s*\{\s*.+\s*\})</token>
            <value>public Boolean is$1\(\)$2
        public Boolean get$1\(\)$2</value>
        </configuration>
    </plugin>
    

    替换:

    public Boolean isProperty() {
        return property;
    }
    

    与:

    public Boolean isProperty() {
        return property;
    }
    public Boolean getProperty() {
        return property;
    }
    

    【讨论】:

      【解决方案2】:

      似乎 jaxws-maven-plugin 使用了已安装 JDK 中的 xjc。在添加对 -enableIntrospection 的支持之前,最新的 Oracle JDK 仍然包含一个 XJC 版本。

      接下来我研究了使用 JAXB 插件。 turnsout jaxws-maven-plugin 没有提供简单的方法来附加到 XJC 的类路径,这是加载 JAXB 插件所必需的。

      出于政治原因无法替换 jaxws-maven-plugin(例如“jaxws 是标准,只能使用标准库”)。

      因此,我回退到编写一个在生成后读取源代码的 maven 插件,是吗

      content.replace("public Boolean is", "public Boolean get");
      

      并将源文件写回磁盘。这也让我能够注入 equals()hashCode() 的定义,这些定义依赖于我正在使用的 API 中业务密钥的命名约定。

      【讨论】:

        【解决方案3】:

        你可以试试

        <enableIntrospection>true</enableIntrospection>
        

        &lt;configuration&gt; 我也可以找到:

        <args>
           <arg>-enableIntrospection</arg>
        </args>
        

        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.14.0</version>
        

        【讨论】:

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