gpt4 book ai didi

maven-3 - org.jooq.codegen.GeneratorException : Error while reading XML configuration

转载 作者:行者123 更新时间:2023-12-03 17:31:44 27 4
gpt4 key购买 nike

我正在尝试从 Java 8 迁移到 Java 10,并面临 JOOQ codegen Maven 插件的以下问题。

我的环境:

  • java 版本“10.0.2” 2018-07-17
  • Apache Maven 3.3.9

  • pom.xml:
            <plugin>
    <groupId>org.jooq</groupId>
    <artifactId>jooq-codegen-maven</artifactId>
    <version>3.11.5</version>
    <executions>
    <execution>
    ...
    <goals>
    <goal>generate</goal>
    </goals>
    </execution>
    </executions>
    <dependencies>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>${mysql-version}</version>
    </dependency>
    <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
    </dependency>
    <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.11</version>
    </dependency>
    <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.11</version>
    </dependency>
    <dependency>
    <groupId>javax.activation</groupId>
    <artifactId>javax.activation-api</artifactId>
    <version>1.2.0</version>
    </dependency>
    <dependency>
    <groupId>org.jooq</groupId>
    <artifactId>jooq-codegen</artifactId>
    <version>3.11.5</version>
    </dependency>
    <dependency>
    <groupId>org.jooq</groupId>
    <artifactId>jooq-meta</artifactId>
    <version>3.11.5</version>
    </dependency>
    </dependencies>
    <configuration>
    <configurationFile>target/my_conf.xml</configurationFile>
    </configuration>
    </plugin>

    my_conf.xml 看起来像这样:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">

    <jdbc>
    <driver>com.mysql.jdbc.Driver</driver>
    <url>jdbc:mysql://${host}/${db_name}</url>
    <user>${user_username}</user>
    <password>${pwds}</password>
    </jdbc>

    <generator>
    <database>
    <name>org.jooq.meta.mysql.MySQLDatabase</name>
    <inputSchema>${db.sf_write_junit_db_name}</inputSchema>
    ...

    </generator>
    </configuration>

    执行后我看到以下异常:
    [ERROR] Failed to execute goal org.jooq:jooq-codegen-maven:3.11.5:generate (jooq-generator-sf_read) on project sf-write-model: Execution jooq-generator-sf_read of goal org.jooq:jooq-codegen-maven:3.11.5:generate failed: org.jooq.codegen.GeneratorException: Error while reading XML configuration: unexpected element (uri:"http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd", local:"configuration"). Expected elements are <{}configuration> -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jooq:jooq-codegen-maven:3.11.5:generate (jooq-generator-sf_read) on project sf-write-model: Execution jooq-generator-sf_read of goal org.jooq:jooq-codegen-maven:3.11.5:generate failed: org.jooq.codegen.GeneratorException: Error while reading XML configuration
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    ...
    Caused by: org.apache.maven.plugin.PluginExecutionException: Execution jooq-generator-sf_read of goal org.jooq:jooq-codegen-maven:3.11.5:generate failed: org.jooq.codegen.GeneratorException: Error while reading XML configuration
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
    Caused by: java.lang.RuntimeException: org.jooq.codegen.GeneratorException: Error while reading XML configuration
    at org.jooq.codegen.maven.Plugin.execute(Plugin.java:144)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 21 more
    Caused by: org.jooq.codegen.GeneratorException: Error while reading XML configuration
    at org.jooq.codegen.GenerationTool.load(GenerationTool.java:925)
    at org.jooq.codegen.maven.Plugin.execute(Plugin.java:139)
    ... 22 more
    Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd", local:"configuration"). Expected elements are <{}configuration>
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:740)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:262)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:257)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:124)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1148)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:573)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:555)
    at com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:102)
    at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:168)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:613)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3058)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:821)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:532)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:258)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:229)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:170)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:219)
    at org.jooq.codegen.GenerationTool.load(GenerationTool.java:922)

    但是当我放入来自 的内容时它工作正常my_conf.xml 内部元素而不是使用:
    <configurationFile>target/my_conf.xml</configurationFile>

    这两个选项给出了相同的异常(exception):
    <!-- Option 1 -->
    <dependency>
    <groupId>javax.activation</groupId>
    <artifactId>javax.activation-api</artifactId>
    <version>1.2.0</version>
    </dependency>
    <dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.0.1</version>
    </dependency>

    <!-- Option 2 -->
    <dependency>
    <groupId>javax.activation</groupId>
    <artifactId>javax.activation-api</artifactId>
    <version>1.2.0</version>
    </dependency>
    <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0</version>
    </dependency>
    <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
    </dependency>

    任何想法为什么以这种方式工作以及如何使用单独的外部文件进行 JOOQ 配置?

    谢谢。

    最佳答案

    @卢卡斯埃德

    此代码适用于 Maven 3.6.0、Jdk 9.0.4、jOOQ 版本 3.10.2、jaxb-api 2.3.1、org.glassfish.jaxb:jaxb-runtime 2.3.1:

    package org.jooq.util;

    public class GenerationTool {

    public static Configuration load(InputStream in) throws IOException {
    ...

    JAXBContext ctx = JAXBContext.newInstance(Configuration.class);
    Unmarshaller unmarshaller = ctx.createUnmarshaller();
    unmarshaller.setSchema(schema);
    unmarshaller.setEventHandler(new ValidationEventHandler() {
    @Override
    public boolean handleEvent(ValidationEvent event) {
    log.warn("Unmarshal warning", event.getMessage());
    return true;
    }
    });

    final SAXParserFactory sax = SAXParserFactory.newInstance();
    sax.setNamespaceAware(false);
    final XMLReader reader = sax.newSAXParser().getXMLReader();
    final Source er = new SAXSource(reader, new InputSource(new StringReader(xml)));
    return (Configuration) unmarshaller.unmarshal(er);
    }
    }

    关于maven-3 - org.jooq.codegen.GeneratorException : Error while reading XML configuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52642516/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com