简体   繁体   English

如何让JAXB2发出CamelCase绑定?

[英]How can I get JAXB2 to emit CamelCase bindings?

I'm generating Java classes from a WSDL using the jaxws-maven-plugin's wsimport goal. 我正在使用jaxws-maven-plugin的wsimport目标从WSDL生成Java类。 Out of the box, this generates hideous classes and methods from the XML schema; 开箱即用,这会从XML模式生成可怕的类和方法; eg, a class called MYOBJECT from an XML element named MY_OBJECT. 例如,来自名为MY_OBJECT的XML元素的名为MYOBJECT的类。

I've found that I can customize my JAXB2 bindings with an external file; 我发现我可以使用外部文件自定义JAXB2绑定 ; this would be acceptable for a small number of classes and methods, but the overhead of manually naming everything in this case is undesirable. 这对于少数类和方法是可以接受的,但是在这种情况下手动命名所有内容的开销是不合需要的。

Some searching uncovers references to an XJC CamelCase Always plugin, but this appears to be unmaintained and most links are 404s. 一些搜索揭示了对XJC CamelCase Always插件的引用,但这似乎没有维护,大多数链接都是404。 Not willing to give up, I did find a camelcase-always Maven artifact which appears to provide this functionality, but I'm not sure how to configure this so that jaxws-maven-plugin uses it. 不愿意放弃,我确实找到了一个似乎提供此功能的camelcase-always Maven工件,但我不知道如何配置它以便jaxws-maven-plugin使用它。

How can I get CamelCase bindings without specifying them all manually? 如何在不指定全部手动的情况下获取CamelCase绑定?

I didn't find examples of how to do this with jaxws-maven-plugin , but I did find examples using the maven-jaxb2-plugin . 我没有找到如何使用jaxws-maven-plugin执行此操作的示例,但我确实找到了使用maven-jaxb2-plugin示例。

First, you need a repository added to your POM: 首先,您需要在POM中添加一个存储库:

<repository>
    <id>releases</id>
    <name>Releases</name>
    <url>https://oss.sonatype.org/content/repositories/releases</url>
</repository>

Note the plugin declaration and arguments added to the maven-jaxb2-plugin execution. 请注意添加到maven-jaxb2-plugin执行的插件声明和参数。

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.8.0</version>
    <executions>
        <execution>
            <id>jaxb-generate</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <generatePackage>YOUR.PACKAGE.HERE</generatePackage>
        <args>
            <arg>-camelcase-always</arg>
        </args>
        <bindingDirectory>src/main/binding</bindingDirectory>
        <schemas>
            <schema>
                <url>http://YOUR.WSDL.HERE</url>
            </schema>
        </schemas>
        <extension>true</extension>
        <plugins>
            <plugin>
                <groupId>org.andromda.thirdparty.jaxb2_commons</groupId>
                <artifactId>camelcase-always</artifactId>
                <version>1.0</version>
            </plugin>
        </plugins>
    </configuration>
</plugin>

See the docs for more details. 有关更多详细信息,请参阅文档

Might be useful for users of Apache CXF and the cxf-xjc-plugin. 可能对Apache CXF和cxf-xjc-plugin的用户有用。

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-xjc-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
      <extensions>
        <extension>org.andromda.thirdparty.jaxb2_commons:camelcase-always:1.0</extension>
      </extensions>
    </configuration>
    <executions>
      <execution>
        <id>generate-sources</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>xsdtojava</goal>
        </goals>
        <configuration>
          <sourceRoot>${basedir}/target/generated-sources/cxf</sourceRoot>
          <xsdOptions>
            <xsdOption>
              <xsd>YOUR.XSD.HERE</xsd>
              <packagename>YOUR.PACKAGE.HERE</packagename>
              <extensionArgs>
                <extensionArg>-camelcase-always</extensionArg>
              </extensionArgs>
              <extension>true</extension>
            </xsdOption>
          </xsdOptions>
        </configuration>
      </execution>
    </executions>
  </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM