Jaxb不保留包中的命名空间大小写

Phi*_*hil 5 java xml xsd jaxb maven

我正在使用codehaus jaxb2-maven-plugin,v1.5将XSD编译为POJO,但生成的包名称将包名称强制为小写(因此,如果我的目标命名空间为http://example.com/sampleNamespace,则生成的包是com.example.samplenamespace).

我已经google了一下,发现大多数人都有下划线问题,以及解决方案,但我似乎无法找到特定的东西来保留命名空间的情况.

注意:我不想重复自己并覆盖生成的包名称,因此maven配置中的generatePackage选项不适合我.

在找到下划线的重复之前,我曾尝试过,还有一个常规空间 - 两者都在那里贴了一个点.

有任何想法吗?

架构:

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:t="http://example.com/sampleNamespace" targetNamespace="http://example.com/sampleNamespace"
jaxb:version="2.0">

    <complexType name="MyFirstClass">
        <sequence>
            <element name="MyFirstElement" type="string" />
        </sequence>
    </complexType>
</schema>
Run Code Online (Sandbox Code Playgroud)

Maven配置:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

bdo*_*han 1

如果您不想使用 JAXB 基于常见 Java 编码转换生成的包名称,则需要利用 JAXB 绑定文件来指定包名称。

<bindings 
  xmlns="http://java.sun.com/xml/ns/jaxb" 
  version="2.1">
  <bindings schemaLocation="schema.xsd">
    <schemaBindings>
      <package name="com.example.sampleNamespace"/>
    </schemaBindings>
  </bindings>
</bindings>
Run Code Online (Sandbox Code Playgroud)