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

无法获取公共无参数构造函数

韦睿
2023-03-14

最近,我将Paho MQTT Spy项目导入Eclipse。导入结束时出现错误:

building has encouted a problem. An internal error occured during: "Build"

An internal error occurred during: "Building".
com.sun.tools.xjc.Plugin: com.sun.tools.xjc.addon.accessors.PluginImpl Unable to get public no-arg constructor

为什么我会收到这条信息,这意味着什么?怎么修?

我正在使用Java13.0.1

我试图用maven构建mqtt-间谍项目,得到了同样的错误。

我添加了下面的依赖项到pom.xml

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.11</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>activation</artifactId>
    <version>1.1.1</version>
</dependency>

现在pom.xml如下所示:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.eclipse.paho.mqttspy</groupId>
    <artifactId>mqtt-spy</artifactId>
    <version>1.0.1-beta</version>
    <packaging>jar</packaging>

    <name>mqtt-spy</name>
    <url>https://github.com/eclipse/paho.mqtt-spy</url>

    <scm>
        <connection>scm:git:../.git</connection>
        <url>../.git</url>
    </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.build.number>${buildNumber}</project.build.number>

        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>yyyy</maven.build.timestamp.format>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>

        <jaxb2.plugin.version>0.12.1</jaxb2.plugin.version>
        <jaxb2.basics.version>0.11.1</jaxb2.basics.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</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>activation</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx</artifactId>
            <version>11</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.eclipse.paho.mqttspy</groupId>
            <artifactId>spy-common</artifactId>
            <version>1.0.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.eclipse.paho.mqttspy</groupId>
            <artifactId>spy-common-ui</artifactId>
            <version>1.0.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.eclipse.paho.mqttspy</groupId>
            <artifactId>mqtt-spy-common</artifactId>
            <version>1.0.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-artifact</artifactId>
            <version>3.0</version>
        </dependency>

        <!--=== TEST === -->

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>2.1_3</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jmock</groupId>
            <artifactId>jmock-legacy</artifactId>
            <version>2.5.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.objenesis</groupId>
            <artifactId>objenesis</artifactId>
            <version>1.0</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>

        <finalName>${project.artifactId}-${project.version}-b${buildNumber}</finalName>

        <!-- Populate version number in the properties file -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/mqtt-spy.properties</include>
                </includes>
            </resource>

            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>**/mqtt-spy.properties</exclude>
                </excludes>
            </resource>

        </resources>

        <plugins>

            <!-- Exclude files -->
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>package-client</id>
                        <phase>package</phase>
                        <configuration>
                            <classifier>exclusions</classifier>
                            <excludes>
                                <exclude>**/log4j.properties</exclude>
                            </excludes>
                        </configuration>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Create a runnable jar with all dependencies -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>pl.baczkowicz.mqttspy.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Generate build number -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <doCheck>true</doCheck>
                    <doUpdate>true</doUpdate>
                    <buildNumberPropertiesFileLocation>buildNumber.properties</buildNumberPropertiesFileLocation>
                    <format>{0,number,###}</format>
                    <items>
                        <item>buildNumber</item>
                    </items>
                </configuration>
            </plugin>

            <!-- Generate JAXB clases -->
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics</artifactId>
                <version>${jaxb2.basics.version}</version>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>${jaxb2.plugin.version}</version>
                <executions>
                    <execution>
                        <id>configuration</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <locale>en</locale>
                            <schemaDirectory>src/main/resources/</schemaDirectory>
                            <schemaIncludes>
                                <include>mqtt-spy-configuration.xsd</include>
                            </schemaIncludes>

                            <!-- Default to the schemaDirectory -->
                            <bindingDirectory>src/main/resources</bindingDirectory>
                            <bindingIncludes>
                                <include>**/mqtt-spy-configuration-bindings.xjb</include>
                            </bindingIncludes>

                            <generateDirectory>src/main/java/</generateDirectory>
                            <generatePackage>pl.baczkowicz.mqttspy.configuration.generated</generatePackage>
                            <removeOldOutput>false</removeOldOutput>

                            <strict>false</strict>
                            <catalogs>
                                <catalog>
                                    <dependencyResource>
                                        <groupId>org.eclipse.paho.mqttspy</groupId>
                                        <artifactId>mqtt-spy-common</artifactId>
                                        <resource>mqtt-spy-common.catalog</resource>
                                    </dependencyResource>
                                </catalog>
                                <catalog>
                                    <dependencyResource>
                                        <groupId>org.eclipse.paho.mqttspy</groupId>
                                        <artifactId>spy-common</artifactId>
                                        <resource>spy-common.catalog</resource>
                                    </dependencyResource>
                                </catalog>
                            </catalogs>

                            <episode>true</episode>
                            <!-- <episodeFile>src/main/java/META-INF/mqtt-spy-configuration.episode</episodeFile> -->

                            <episodes>
                                <episode>
                                    <groupId>org.eclipse.paho.mqttspy</groupId>
                                    <artifactId>mqtt-spy-common</artifactId>
                                </episode>
                                <episode>
                                    <groupId>org.eclipse.paho.mqttspy</groupId>
                                    <artifactId>spy-common</artifactId>
                                </episode>
                            </episodes>

                            <args>
                                <arg>-XtoString</arg>
                                <arg>-Xequals</arg>
                                <arg>-XhashCode</arg>
                                <arg>-Xcopyable</arg>
                                <arg>-Xvalue-constructor</arg>
                            </args>
                            <plugins>
                                <plugin>
                                    <groupId>org.jvnet.jaxb2_commons</groupId>
                                    <artifactId>jaxb2-basics</artifactId>
                                    <version>${jaxb2.basics.version}</version>
                                </plugin>
                            </plugins>
                        </configuration>
                    </execution>

                    <execution>
                        <id>stats</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <locale>en</locale>
                            <schemaDirectory>src/main/resources/</schemaDirectory>
                            <schemaIncludes>
                                <include>mqtt-spy-stats.xsd</include>

                            </schemaIncludes>

                            <!-- Default to the schemaDirectory -->
                            <bindingDirectory>src/main/resources</bindingDirectory>
                            <bindingIncludes>
                                <include>**/mqtt-spy-stats-bindings.xjb</include>
                            </bindingIncludes>

                            <generateDirectory>src/main/java/</generateDirectory>
                            <generatePackage>pl.baczkowicz.mqttspy.stats.generated</generatePackage>
                            <removeOldOutput>false</removeOldOutput>

                            <episode>false</episode>
                            <!-- <episodeFile>src/main/java/META-INF/mqtt-spy-stats.episode</episodeFile> -->

                            <args>
                                <arg>-XtoString</arg>
                                <arg>-Xequals</arg>
                                <arg>-XhashCode</arg>
                                <arg>-Xcopyable</arg>
                            </args>
                            <plugins>
                                <plugin>
                                    <groupId>org.jvnet.jaxb2_commons</groupId>
                                    <artifactId>jaxb2-basics</artifactId>
                                    <version>${jaxb2.basics.version}</version>
                                </plugin>
                            </plugins>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-value-constructor</artifactId>
                        <version>3.0</version>
                    </dependency>
                </dependencies>
            </plugin>

            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.3</version>
                <executions>
                    <execution>
                        <id>replace</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <basedir>${basedir}/src/main/java</basedir>
                    <includes>
                        <include>pl/baczkowicz/mqttspy/configuration/generated/**/*.java</include>
                        <include>pl/baczkowicz/mqttspy/stats/generated/**/*.java</include>
                    </includes>
                    <replacements>
                        <replacement>
                            <token>//${line.separator}// This file was generated by the
                                JavaTM</token>
                            <value>//
                                // Copyright (c) ${maven.build.timestamp} Kamil Baczkowicz
                                //
                                // CSOFF: a.*
                                // This file was generated by the JavaTM</value>
                        </replacement>
                        <replacement>
                            <token>^ \*/</token>
                            <value> */
                                @SuppressWarnings("all")</value>
                        </replacement>
                        <replacement>
                            <token>^// Generated on.*$</token>
                            <value>// Timestamp removed by maven-replacer-plugin to avoid
                                detecting changes - see the project POM for details</value>
                        </replacement>
                    </replacements>
                    <regex>true</regex>
                    <quiet>false</quiet>
                    <regexFlags>
                        <regexFlag>MULTILINE</regexFlag>
                    </regexFlags>
                </configuration>
            </plugin>

        </plugins>

    </build>

</project>

Maven给出了错误:

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.eclipse.paho.mqttspy:mqtt-spy:jar:1.0.1-beta
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 162, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -----------------< org.eclipse.paho.mqttspy:mqtt-spy >------------------
[INFO] Building mqtt-spy 1.0.1-beta
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for com.sun.xml.bind:jaxb-core:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for com.sun.xml.bind:jaxb-impl:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.eclipse.paho.mqttspy:spy-common:jar:1.0.1 is missing, no dependency information available
[WARNING] The POM for org.eclipse.paho.mqttspy:spy-common-ui:jar:1.0.1 is missing, no dependency information available
[WARNING] The POM for org.eclipse.paho.mqttspy:mqtt-spy-common:jar:1.0.1 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.384 s
[INFO] Finished at: 2020-01-08T16:10:33+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project mqtt-spy: Could not resolve dependencies for project org.eclipse.paho.mqttspy:mqtt-spy:jar:1.0.1-beta: The following artifacts could not be resolved: org.eclipse.paho.mqttspy:spy-common:jar:1.0.1, org.eclipse.paho.mqttspy:spy-common-ui:jar:1.0.1, org.eclipse.paho.mqttspy:mqtt-spy-common:jar:1.0.1: Failure to find org.eclipse.paho.mqttspy:spy-common:jar:1.0.1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

UPD

Java8解决了问题,但我仍然试图使java 13与它一起工作。

正在尝试使用下面定义的pom.xml构建非常根的项目。xml现在包含必需的javax依赖项。

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 

    <name>mqtt-spy project</name> 
    <groupId>pl.baczkowicz.mqttspy</groupId>
    <artifactId>mqtt-spy-pom</artifactId>

    <packaging>pom</packaging> 
    <version>0.0.1-SNAPSHOT</version> 

    <properties>
        <main.basedir>${project.basedir}</main.basedir>
    </properties>


    <dependencies>  
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</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>activation</artifactId>
            <version>1.1.1</version>
        </dependency>

    </dependencies>

    <!-- Include all modules in correct order. --> 
    <modules> 
        <module>spy-common</module> 
        <module>spy-common-ui</module> 
        <module>mqtt-spy-common</module> 
        <module>mqtt-spy-daemon</module>
        <module>mqtt-spy</module>  
    </modules> 

</project> 

得到相同的错误:

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.eclipse.paho.mqttspy:mqtt-spy-daemon:jar:1.0.0
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 113, column 15
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.eclipse.paho.mqttspy:mqtt-spy:jar:1.0.1-beta
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 162, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] spy-common                                                         [jar]
[INFO] spy-common-ui                                                      [jar]
[INFO] mqtt-spy-common                                                    [jar]
[INFO] mqtt-spy-daemon                                                    [jar]
[INFO] mqtt-spy                                                           [jar]
[INFO] mqtt-spy project                                                   [pom]
[INFO]
[INFO] ----------------< org.eclipse.paho.mqttspy:spy-common >-----------------
[INFO] Building spy-common 1.0.1                                          [1/6]
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for com.sun.xml.bind:jaxb-impl:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for com.sun.xml.bind:jaxb-xjc:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for com.sun.xml.bind:jaxb-core:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-jaxb2-plugin:0.12.1:generate (spy-common) @ spy-common ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] spy-common 1.0.1 ................................... FAILURE [  0.737 s]
[INFO] spy-common-ui 1.0.1 ................................ SKIPPED
[INFO] mqtt-spy-common 1.0.1 .............................. SKIPPED
[INFO] mqtt-spy-daemon 1.0.0 .............................. SKIPPED
[INFO] mqtt-spy 1.0.1-beta ................................ SKIPPED
[INFO] mqtt-spy project 0.0.1-SNAPSHOT .................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.910 s
[INFO] Finished at: 2020-01-08T20:05:25+02:00
[INFO] ------------------------------------------------------------------------

......

---------------------------------------------------
Exception in thread "main" java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: com.sun.tools.xjc.addon.accessors.PluginImpl Unable to get public no-arg constructor
        at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:583)
        at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:674)
        at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1233)
        at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1265)
        at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
        at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
        at com.sun.tools.xjc.Options.findServices(Options.java:960)
        at com.sun.tools.xjc.Options.getAllPlugins(Options.java:374)
        at com.sun.tools.xjc.Options.parseArgument(Options.java:688)
        at com.sun.tools.xjc.Options.parseArguments(Options.java:812)
        at org.jvnet.mjiip.v_2.OptionsFactory.createOptions(OptionsFactory.java:87)
        at org.jvnet.mjiip.v_2.OptionsFactory.createOptions(OptionsFactory.java:18)
        at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:462)
        at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:311)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
        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:56)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlAccessType
        at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3138)
        at java.base/java.lang.Class.getConstructor0(Class.java:3343)
        at java.base/java.lang.Class.getConstructor(Class.java:2152)
        at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:661)
        at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:658)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
        at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:669)
        ... 34 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlAccessType
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        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)
        ... 42 more

共有3个答案

巫马望
2023-03-14

为了补充上述答案,我遇到了同样的问题,并且能够通过将JAVA_HOME环境变量从JDK11更改为JDK8来解决。

我将检查环境变量以及您的IDEJava设置和项目中的Java版本。

姬俊驰
2023-03-14

显然,这是由于没有使用JAVA 8或更高版本。

下面是一个关于如何在Eclipse中处理这个问题的例子

更多细节

例外情况似乎来自另一个根本原因:

Caused by: java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: com.sun.tools.xjc.addon.accessors.PluginImpl Unable to get public no-arg constructor
...
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlAccessType

较新的java版本似乎带有此缺陷。

您可以通过两个选项解决问题

1)添加模块依赖关系

--add-modules java.xml.bind
--add-modules java.se.ee

这将适用于Java9和更高版本,但会破坏与Java8和更低版本的兼容性——添加模块对他们来说是未知的。

2)在POM. XML中添加库作为依赖项

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.11</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>activation</artifactId>
    <version>1.1.1</version>
</dependency>

编辑:

据我们所知,maven中没有名为org.eclipse.paho.mqttspy

从Paho间谍维基唯一的依赖是MQTTV客户端

尝试更改您的依赖项,并改为包括:

<dependency>
  <groupId>org.eclipse.paho</groupId>
  <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
  <version>1.2.2</version>
  <type>eclipse-plugin</type>
</dependency>

由于找不到依赖项,您的构建似乎也会失败:

[错误]无法在项目mqtt-spi上执行目标:无法解决项目org.eclipse.paho.mqttspy的依赖项:mqtt-spi:jar:1.0.1-beta:无法解决以下工件:org.eclipse.paho.mqttspy:spy-普通型:jar:1.0.1,org.eclipse.paho.mqttspy:spy-plus-ui:jar:1.0.1,org.eclipse.paho.mqttspy: mqtt-spy-通用: jar: 1.0.1:找不到org.eclipse.paho.mqttspy: spy-通用: jar: 1.0.1在https://repo.maven.apache.org/maven2被缓存在本地存储库中,解析将不会被重新尝试,直到中央的更新间隔已经过去或更新被迫-

编辑2:

试着检查你的间谍版本。以前的版本对于JDK似乎也有同样的问题

许亦
2023-03-14

您可能没有使用JAVA 8。请在项目属性中定义Java8,并尝试再次构建它。如果您使用的是Java9或更高版本,因为他们放弃了类路径的使用,您需要添加--add模块java.xml.bind作为JVM参数,以便连接模块

 类似资料:
  • 问题内容: 在编组期间,JAXB需要一个公共的无参数构造函数吗? 我正在传递一个对象,而不是一个类。为什么JAXB需要构造函数?要构造什么? 问题答案: 在执行封送操作期间,JAXB实现不应需要无参数构造函数。JAXB确实需要一个解组。通常,在创建JAXBContext时,缺少no- arg构造函数会导致错误。您正在使用的JAXB实现可能会延迟初始化,直到执行实际操作为止。 通常,在将来的JAXB

  • 我正在浏览hibernate留档,文档说hibernate需要为我们所有的持久类提供一个no-arg构造函数: 无参数构造函数是所有持久类的要求;Hibernate必须使用Java反射为您创建对象。构造器可以是私有的,但是在没有字节码插装的情况下,运行时代理生成和有效的数据检索需要包或公共可见性。 但是当我通过创建一个没有任何无参数构造函数的POJO类并放置一个接受参数的构造函数来创建一个示例程序

  • 问题内容: 我有一个用JUnit4语法编写的测试类,可以使用“以junit测试方式运行”选项在eclipse中运行而不会失败。通过蚂蚁目标运行相同的测试时,出现以下错误: 我在类中没有public no arg构造函数,但这真的有必要吗? 这是我的蚂蚁目标 测试类没有构造函数,但是它具有带有默认修饰符的内部类。它也有一个匿名内部类。两个内部类均给出“ Test类应具有公共零参数构造函数错误”。我正

  • 我一直遵循这个非常有效的教程,直到我修改了我的,增加了一个构造函数。我现在对决议有问题,不知道该怎么做才能解决这个问题。有没有一种简单的方法来强制它获取无参数构造函数,或者我的方法不正确? 有两个构造函数: 构造函数: 仓库: 代码: WebApiConfig: WebApi调用出错: 系统。无效操作异常:尝试创建SiteController类型的控制器时出错。确保控制器具有无参数公共构造函数。

  • 使用Gradle 7.1.1、Java 16、Groovy 3.0.8和Spock 2.0-Groovy3.0 如有任何帮助,不胜感激。 ps.这适用于Java11、Groovy2.5和Spock1.3-Groovy-2.5

  • 问题内容: 我的一项作业需要一个银行帐户才能从支票和储蓄帐户转帐资金。交易存储在ArrayList中,并设置为用户指定何时转移资金。用于支票和储蓄的银行帐户类可以正常工作,但是我创建的TransferService类在NetBeans中不能正确编译。 这些提示似乎无法解决错误。我得到错误: 事务是抽象的,无法实例化。 我该如何解决这个问题? 问题答案: 构造函数没有返回类型。所以不 反而 关于,