当前位置: 首页 > 知识库问答 >
问题:

如果已经创建了xsd元素,则将其排除在解组之外?

柯苗宣
2023-03-14
A class/interface with the same name "org.somePackage.customer" is already in use.
    Use a class customization to resolve this conflict.
        at com.sun.tools.xjc.util.CodeModelClassFactory.createClass(CodeModelClassFactory.java:121)
        at com.sun.tools.xjc.util.CodeModelClassFactory.createClass(CodeModelClassFactory.java:82)
        at com.sun.tools.xjc.generator.bean.ImplStructureStrategy$1.createClasses(ImplStructureStrategy.java:82)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassDef(BeanGenerator.java:437)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.getClazz(BeanGenerator.java:469)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:194)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:166)
        at com.sun.tools.xjc.model.Model.generateCode(Model.java:290)
        at org.jvnet.mjiip.v_2_2.XJC22Mojo.generateCode(XJC22Mojo.java:70)
 <xsd:element name="customer" >
         ........
 </xsd:element>
 <xsd:element name="permanentCustomer" type="customer"/>
    <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.8.3</version>
            <configuration>
                <schemaDirectory>src/main/resources/META-INF/schema</schemaDirectory>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
<xsd:element name="customer" block="substitution">
 ........
</xsd:element>
<xsd:element name="permanentCustomer" type="customer"/>

在对net进行研究之后,我猜想jaxb编译器再次尝试基于元素name=“permanentCustomer”创建customer类,它已经基于元素name=“customer”创建了该类。所以我不想在解组时为permanentCustomer创建java对象,因为它已经在创建customer时创建了。

我能想到两个解决办法

1)maven-jaxb2-plugin插件的一些配置,如果java类已经生成,就不要重新生成,继续

是否存在任何配置?

共有1个答案

燕智
2023-03-14

这是一个xjc问题,不是我(diclaimer)碰巧是maven-jaxb2-plugin的作者。

因为已经为customer类型生成了customer元素的customer类,所以忽略为其生成customer类不是一个好主意,因为它们是不同的概念。治标不治本。

核心问题是XJC尝试为customer元素创建类,这导致命名冲突。因此,要么不要为customer元素生成类,要么处理命名冲突。

<jaxb:bindings 
    schemaLocation="..." 
    node="/xs:schema">

    <jaxb:bindings node="xs:element[@name='customer']">
        <jaxb:class name="CustomerElement"/>
    </jaxb:bindings>
</jaxb:bindings>

或者,您可以对名称转换使用全局自定义,请参见以下答案:

https://stackoverflow.com/a/21685303/303810

类似于:

 类似资料:
  • 问题内容: 我正在处理一个请求,其中我必须创建一个表来插入一些数据。因此,显然我将首先拥有一个删除表st。在创建圣之前 但是,当我第一次运行此程序(可以创建表之前)时,它将弹出一个错误,提示未创建表,然后从此处创建表和goe子。因此,每当有人第一次运行我的代码时,它将在放置表st上弹出此错误。有谁有更好的主意吗? 诸如“如果表存在则删除其他创建表”之类的东西, 我不确定我们如何在sql中做到这一点

  • 我有以下elasticsearch索引结构: 其思想是为每个用户id-message\u id插入带有操作“open”的记录,该用户id-message\u id缺少带有操作“open”的记录。为此,我需要获取所有user\u id-message\u id关联,前提是它们没有动作:“open”。 是否可以创建一个查询,返回不同的user_id-message_id记录不包括user_id-mes

  • 有人帮忙吗? 提前道谢。

  • 问题内容: 如果删除了DOM元素,它的侦听器也会从内存中删除吗? 问题答案: 现代浏览器 纯JavaScript 如果删除的DOM元素是无引用的(没有指向它的引用),则是垃圾收集器以及与之关联的任何事件处理程序/侦听器都会拾取该元素本身。 然而; 如果仍然有引用指向该元素,则该元素及其事件侦听器将保留在内存中。 jQuery 假设jQuery中的相关方法(例如)将以完全相同的方式起作用(考虑是使用

  • 您好帮助请把xml文件放在里面一些相同的元素,这些元素的内容不同,“name”属性。这些元素有不同的项目集,如何进行解咒?断续器: 我需要在Cdb和FmssSc中执行对象2的解组。我的尝试:通用元素-ServiceBroker.class 适配器.class Cdb.class FmssSc.class 演示: 错误:

  • 问题内容: 我很沮丧,我不知道该怎么做。 基本上,我只想创建一个表,但是如果它存在,则需要将其删除并重新创建,而不是将其截断,但是如果不存在,则可以创建它。 有人可以帮忙吗? 谢谢乔治 问题答案: 放在tablename您的发言之前。 该语句将删除该表(如果存在),但如果不存在则不会引发错误。