如何让 JAXB2 发出 CamelCase 绑定? [英] How can I get JAXB2 to emit CamelCase bindings?

查看:25
本文介绍了如何让 JAXB2 发出 CamelCase 绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

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

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.

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

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

推荐答案

我没有找到有关如何使用 jaxws-maven-plugin 执行此操作的示例,但我确实找到了使用 <代码>maven-jaxb2-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.

首先,您需要在 POM 中添加一个存储库:

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>

注意添加到 maven-jaxb2-plugin 执行中的插件声明和参数.

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.

这篇关于如何让 JAXB2 发出 CamelCase 绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆