如何让 JAXB2 发出 CamelCase 绑定?

发布于 2024-12-27 17:40:11 字数 890 浏览 5 评论 0原文

我使用 jaxws-maven-plugin 的 wsimport 目标。开箱即用,这会从 XML 模式生成丑陋的类和方法;例如,来自名为 MY_OBJECT 的 XML 元素的名为 MYOBJECT 的类。

我发现我可以 自定义我的JAXB2 与外部文件的绑定;这对于少量的类和方法来说是可以接受的,但是在这种情况下手动命名所有内容的开销是不可取的。

一些搜索发现对 XJC CamelCase Always 插件,但这似乎没有维护,大多数链接都是 404。不愿意放弃,我确实找到了一个 camelcase-always Maven 工件似乎提供了此功能,但我不确定如何配置它以便 jaxws-maven-plugin 使用它。

如何在不手动指定所有绑定的情况下获取 CamelCase 绑定?

I'm generating Java classes from a WSDL using the jaxws-maven-plugin's wsimport goal. Out of the box, this generates hideous classes and methods from the XML schema; e.g., a class called MYOBJECT from an XML element named MY_OBJECT.

I've found that I can customize my JAXB2 bindings with an external file; 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. 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.

How can I get CamelCase bindings without specifying them all manually?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百思不得你姐 2025-01-03 17:40:12

我没有找到如何使用 jaxws-maven-plugin 执行此操作的示例,但我确实找到了使用 maven-jaxb2-plugin 的示例。

首先,您需要将存储库添加到 POM:

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

注意添加到 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>

有关更多详细信息,请参阅文档

I didn't find examples of how to do this with jaxws-maven-plugin, but I did find examples using the maven-jaxb2-plugin.

First, you need a repository added to your 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.

<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.

过去的过去 2025-01-03 17:40:12

可能对 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>

Might be useful for users of Apache CXF and the 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文