简体   繁体   English

xmlbeans-maven-plugin 不为列表生成 getter

[英]xmlbeans-maven-plugin not generating getters for Lists

I'm currently trying to build a legacy project which has been migrated from Ant to Maven. This project uses the xmlbeans-maven-plugin to build java classes from .xsd source files.我目前正在尝试构建一个已从 Ant 迁移到 Maven 的遗留项目。该项目使用xmlbeans-maven-plugin.xsd源文件构建 java 类。 Everything works fine until a get...List() method gets called.在调用get...List()方法之前一切正常。 All List-getters seem to be missing.所有的 List-getters 似乎都不见了。 All the information I could find points to a Java version being used that does not support Lists.我能找到的所有信息都指向正在使用的不支持列表的 Java 版本。 The solution that worked for most people was changing the javaSource tag in the plugin configuration to 1.5 .适用于大多数人的解决方案是将插件配置中的javaSource标记更改为1.5 This did not solve my problem.这并没有解决我的问题。

The relevant part of my pom.xml currently looks like this:我的pom.xml的相关部分目前看起来像这样:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xmlbeans-maven-plugin</artifactId>
    <version>2.3.3</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>xmlbeans</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <javaSource>1.8</javaSource>
        <schemaDirectory>src/main/xsd</schemaDirectory>
    </configuration>
</plugin>

Another stackoverflow thread ( Maven2:List return type methods not getting generated from.xsd files while using xmlbeans plugin ), from 2011 mind you, suggests to set the Java version to 1.5 instead.请注意,从 2011 年开始,另一个 stackoverflow 线程( Maven2:List 返回类型方法未从 .xsd 文件生成,同时使用 xmlbeans 插件)建议将 Java 版本设置为 1.5。 This gives me another error:这给了我另一个错误:

Failed to execute goal org.codehaus.mojo:xmlbeans-maven-plugin:2.3.3:xmlbeans (default) on project ...: XmlBeans compile failed:
 xml ErrorLoading schema file ...
 xml ErrorLoading schema file ...
 xml ErrorLoading schema file ...
 xml ErrorLoading schema file ...
 xml ErrorLoading schema file ...

The solution for this problem I found here tells me this is a problem with Java 11 and that I should set the Java version to 1.8.我在这里找到的这个问题的解决方案告诉我这是 Java 11 的问题,我应该将 Java 版本设置为 1.8。

Here's a snippet of one of the .xsd files:这是.xsd文件之一的片段:

<xs:element name="DbcFile" minOccurs="0" maxOccurs="unbounded">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="name" type="xs:string" />
      <xs:element name="path" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

This should generate a method called getDbcFileList() .这应该生成一个名为getDbcFileList()的方法。 However, as you can see from this error message, it does not do that:但是,正如您从这个错误消息中看到的那样,它并没有这样做:

... cannot find symbol
  symbol:   method getDbcFileList()

It does generate getDbcFileArray() .它确实生成getDbcFileArray() I have tried a lot of combinations of changing Java versions, removing the build folder every time to get a clean build, you name it.我尝试了很多更改 Java 版本的组合,每次都删除构建文件夹以获得干净的构建,随便你怎么说。 I'm honestly out of ideas.老实说,我没有想法。

I'm using Maven 3.6.3 and OpenJDK 13.0.2+8_2.我正在使用 Maven 3.6.3 和 OpenJDK 13.0.2+8_2。 I'm running maven commands from IntelliJ 2020.1.我正在从 IntelliJ 2020.1 运行 maven 命令。 The only thing I haven't tried is downgrading my JDK, but I feel like that won't make a difference.我唯一没有尝试过的是降级我的 JDK,但我觉得这不会有什么不同。

I solved it.我解决了。 The solution was to downgrade to JDK 1.8, for some reason.出于某种原因,解决方案是降级到 JDK 1.8。

I got this error when upgrading from JDK 1.8 to JDK 11. The xmlbeans-maven-plugin is old but if you have to stick with it then the solution is to add following attributes to <configuration> section for the plugin in pom.xml :从 JDK 1.8 升级到 JDK 11 时出现此错误。xmlbeans-maven-plugin 很旧,但如果您必须坚持使用它,那么解决方案是将以下属性添加到pom.xml中插件的<configuration>部分:

<noJavac>true</noJavac>
<javaSource>1.6</javaSource>

The author was close to solution but <javaSource> attribute alone is not enough.作者接近解决方案,但仅<javaSource>属性是不够的。 Setting <noJavac> prevents xmlbeans from calling compilation with argument "-source" pointing to possibly no longer supported Java versions, in my case 1.4.设置<noJavac>可防止 xmlbeans 使用参数“-source”调用编译,该参数指向可能不再支持的 Java 版本,在我的例子中是 1.4。

I see the OP linked the thread where I found solution, but back then the part about javac was missing: https://github.com/ethercis/openehr-java-libs/issues/1#issuecomment-880253566 .我看到 OP 链接了我找到解决方案的线程,但那时缺少关于 javac 的部分: https://github.com/ethercis/openehr-java-libs/issues/1#issuecomment-880253566

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM