【问题标题】:JAXB generating JAXBElement<String> needed StringJAXB 生成 JAXBElement<String> 需要的字符串
【发布时间】:2019-04-09 11:41:04
【问题描述】:

我使用 maven 插件从 wsdl 创建了 java 类,下面提到 pom.xml 中的相关条目

<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>${maven-jaxb2-plugin.version}</version>
<executions>
    <execution>
        <goals>
            <goal>generate</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <generatePackage>om.sd</generatePackage>
    <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
    <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
    <args>
        <arg>-no-header</arg>
    </args>
    <schemaIncludes>
        <include>*.wsdl</include>
    </schemaIncludes>
</configuration>
</plugin>

Java 类已生成。

请求类元素创建为 JAXB 元素而不是 String,我需要手动将其转换为 String。

我有什么方法可以配置,以便将元素创建为 String 而不是 JAXB 元素。

【问题讨论】:

  • stackoverflow.com/questions/12508741/… 可能会对您有所帮助。
  • @Alien 我看到了这个,我创建了 jaxb-bindings.xml。给定的 pom.xl 我在哪里添加这个?
  • @user630209 默认情况下,将绑定文件命名为whatever.xjb 并将其放入src/main/resources。

标签: jakarta-ee jaxb maven-jaxb2-plugin


【解决方案1】:

从链接的问题中获取给定的 sn-p...

<jaxb:bindings ... xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
  <jaxb:globalBindings generateElementProperty="false">
    <xjc:simple />
    <!-- ... -->
  </jaxb:globalBindings>
</jaxb:bindings>

... 并生成包含自定义包装器的自定义 *.xjb 文件。将文件放在架构目录中 - 默认情况下插件应该找到它。

如果您想将文件放入您选择的目录中,只需在 POM 中插件的配置部分中引用它即可。

<bindingDirectory>src/main/resources</bindingDirectory>
<bindingIncludes>
  <include>**/*.xjb</include>
</bindingIncludes>
<bindingExcludes>
  <exclude>**/*.xj</exclude>
</bindingExcludes>

需要更多信息?

[1]https://github.com/highsource/maven-jaxb2-plugin/wiki/Specifying-What-To-Compile

[2]http://websystique.com/java/jaxb/jaxb-codegeneration-maven-example/

【讨论】:

    猜你喜欢
    • 2012-09-12
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多