一尘不染

引起原因:java.lang.ClassNotFoundException:org.jooq.util.jaxb.tools.XMLAppendable- Spring Boot JOOQ

spring-boot

我正在跟踪链接:https :
//sivalabs.in/2016/03/springboot-working-with-
jooq/
并使用Java8Spring Boot 2.2.2.RELEASE

我关注了以下链接:https : //github.com/etiennestuder/gradle-jooq-
plugin/issues/71,但对我没有用。有什么建议吗?

Caused by: java.lang.NoClassDefFoundError: org/jooq/util/jaxb/tools/XMLAppendable
    at java.lang.ClassLoader.defineClass1 (Native Method)
    at java.lang.ClassLoader.defineClass (ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass (SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass (URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100 (URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run (URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run (URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged (Native Method)
    at java.net.URLClassLoader.findClass (URLClassLoader.java:361)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf (ClassRealm.java:401)
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:42)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass (ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:239)
    at java.lang.Class.getDeclaredFields0 (Native Method)
    at java.lang.Class.privateGetDeclaredFields (Class.java:2583)
    at java.lang.Class.getDeclaredFields (Class.java:1916)
    at com.google.inject.spi.InjectionPoint.getInjectionPoints (InjectionPoint.java:675)
    at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields (InjectionPoint.java:380)
    at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies (ConstructorBindingImpl.java:164)
    at com.google.inject.internal.InjectorImpl.getInternalDependencies (InjectorImpl.java:613)
    at com.google.inject.internal.InjectorImpl.cleanup (InjectorImpl.java:569)
    at com.google.inject.internal.InjectorImpl.initializeJitBinding (InjectorImpl.java:555)
    at com.google.inject.internal.InjectorImpl.createJustInTimeBinding (InjectorImpl.java:884)
    at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive (InjectorImpl.java:805)
    at com.google.inject.internal.InjectorImpl.getJustInTimeBinding (InjectorImpl.java:282)
    at com.google.inject.internal.InjectorImpl.getBindingOrThrow (InjectorImpl.java:214)
    at com.google.inject.internal.InjectorImpl.getProviderOrThrow (InjectorImpl.java:1006)
    at com.google.inject.internal.InjectorImpl.getProvider (InjectorImpl.java:1038)
    at com.google.inject.internal.InjectorImpl.getProvider (InjectorImpl.java:1001)
    at com.google.inject.internal.InjectorImpl.getInstance (InjectorImpl.java:1051)
    at org.eclipse.sisu.space.AbstractDeferredClass.get (AbstractDeferredClass.java:48)
    at com.google.inject.internal.ProviderInternalFactory.provision (ProviderInternalFactory.java:81)
    at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision (InternalFactoryToInitializableAdapter.java:53)
    at com.google.inject.internal.ProviderInternalFactory$1.call (ProviderInternalFactory.java:65)
    at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:115)
    at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:133)
    at com.google.inject.internal.ProvisionListenerStackCallback.provision (ProvisionListenerStackCallback.java:68)
    at com.google.inject.internal.ProviderInternalFactory.circularGet (ProviderInternalFactory.java:63)
    at com.google.inject.internal.InternalFactoryToInitializableAdapter.get (InternalFactoryToInitializableAdapter.java:45)
    at com.google.inject.internal.InjectorImpl$2$1.call (InjectorImpl.java:1016)
    at com.google.inject.internal.InjectorImpl.callInContext (InjectorImpl.java:1092)
    at com.google.inject.internal.InjectorImpl$2.get (InjectorImpl.java:1012)
    at org.eclipse.sisu.inject.Guice4$1.get (Guice4.java:162)
    at org.eclipse.sisu.inject.LazyBeanEntry.getValue (LazyBeanEntry.java:81)
    at org.eclipse.sisu.plexus.LazyPlexusBean.getValue (LazyPlexusBean.java:51)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:263)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:255)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo (DefaultMavenPluginManager.java:519)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:121)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)

pom.mxl

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example.jooq</groupId>
    <artifactId>spring-boot-jooq</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-jooq</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
    </properties>

    <profiles>
        <profile>
            <id>h2</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jooq</groupId>
                        <artifactId>jooq-codegen-maven</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>com.h2database</groupId>
                                <artifactId>h2</artifactId>
                                <version>${h2.version}</version>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <jdbc>
                                <driver>org.h2.Driver</driver>
                                <url>jdbc:h2:~/springbootjooq</url>
                            </jdbc>
                            <generator>
                                <name>org.jooq.util.JavaGenerator</name>
                                <database>
                                    <name>org.jooq.util.h2.H2Database</name>
                                    <includes>.*</includes>
                                    <excludes />
                                    <inputSchema>PUBLIC</inputSchema>
                                </database>
                                <target>
                                    <packageName>com.example.jooq.model</packageName>
                                    <directory>gensrc/main/java</directory>
                                </target>
                            </generator>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>mysql</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jooq</groupId>
                        <artifactId>jooq-codegen-maven</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>mysql</groupId>
                                <artifactId>mysql-connector-java</artifactId>
                                <version>${mysql.version}</version>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <jdbc>
                                <driver>com.mysql.jdbc.Driver</driver>
                                <url>jdbc:mysql://localhost:3306/test</url>
                                <user>root</user>
                                <password>root</password>
                            </jdbc>
                            <generator>
                                <name>org.jooq.util.JavaGenerator</name>
                                <database>
                                    <name>org.jooq.util.mysql.MySQLDatabase</name>
                                    <includes>.*</includes>
                                    <excludes />
                                    <inputSchema>test</inputSchema>
                                </database>
                                <target>
                                    <packageName>com.example.jooq.model</packageName>
                                    <directory>gensrc/main/java</directory>
                                </target>
                            </generator>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jooq</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>3.12.3</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>gensrc/main/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

阅读 228

收藏
2020-05-30

共1个答案

一尘不染

您正在显示Maven pom.xml, 并提到 gradle-jooq-plugin 出错。

如果您使用的是Maven,则 org.jooq:jooq:3.12.3中* 存在
org.jooq.util.jaxb.tools.XMLAppendable 类, 该类 已通过添加 spring-boot-
starter-jooq而
添加到了classpath中。
***

我进行了以下修改,并且代码生成工作正常:

  • 重命名org.jooq。 util .JavaGenerator转换为org.jooq。 代码生成 .JavaGenerator
  • 重命名org.jooq。 util .h2.H2Database转换为org.jooq。 .h2.H2Database
  • 重命名org.jooq。 UTIL .mysql.MySQLDatabase到org.jooq。 .mysql.MySQLDatabase
2020-05-30