org.jooq.codegen.GeneratorException: ошибка при чтении конфигурации XML - PullRequest
0 голосов
/ 04 октября 2018

Я пытаюсь перейти с Java 8 на Java 10 и сталкиваюсь со следующей проблемой с плагином JOOQ codegen Maven.

Моя среда:

  1. java версия "10.0.2 "2018-07-17
  2. 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>

Эти два параметра дают одно и то же исключение:

<!-- 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?

Спасибо.

1 Ответ

0 голосов
/ 03 декабря 2018

@ Lukas Eder

Этот код работает для меня с Maven 3.6.0, Jdk 9.0.4, jOOQ версия 3.10.2, jaxb-api 2.3.1, org.glassfish.jaxb: jaxb-runtime2.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);
}
}
...