繁体   English   中英

Java Web 应用程序无法作为 maven 项目运行

[英]Java Web Application Failed to run as maven project

我是 java 的新手。 I am using apache netbeans 12.2 version to create new project and the java version is 17. I followed the step to create java web application with maven but when I build it and try to run it I am getting following errors in the console window.

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project JavaProject: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin: 2.3:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.3' due to an API incompatibility: org.codehaus.plexus.component.repository.exception .ComponentLookupException:null

我在 pom.xml 文件中检查了所需的依赖项,但为什么它无法运行?

这是 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>com.mycompany</groupId>
    <artifactId>JavaProject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>JavaProject-1.0-SNAPSHOT</name>
    
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <jakartaee>8.0</jakartaee>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>${jakartaee}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    
     <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
           
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-api</artifactId>
                                    <version>${jakartaee}</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

这是带有错误消息的整个控制台。

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project JavaProject: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.3' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null
-----------------------------------------------------
realm =    plugin>org.apache.maven.plugins:maven-war-plugin:2.3
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/Users/mohammadhossan/.m2/repository/org/apache/maven/plugins/maven-war-plugin/2.3/maven-war-plugin-2.3.jar
urls[1] = file:/Users/mohammadhossan/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar
urls[2] = file:/Users/mohammadhossan/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar
urls[3] = file:/Users/mohammadhossan/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar
urls[4] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
urls[5] = file:/Users/mohammadhossan/.m2/repository/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.jar
urls[6] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-io/2.0.5/plexus-io-2.0.5.jar
urls[7] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-archiver/2.2/plexus-archiver-2.2.jar
urls[8] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.15/plexus-interpolation-1.15.jar
urls[9] = file:/Users/mohammadhossan/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
urls[10] = file:/Users/mohammadhossan/.m2/repository/com/thoughtworks/xstream/xstream/1.4.3/xstream-1.4.3.jar
urls[11] = file:/Users/mohammadhossan/.m2/repository/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar
urls[12] = file:/Users/mohammadhossan/.m2/repository/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar
urls[13] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.8/plexus-utils-3.0.8.jar
urls[14] = file:/Users/mohammadhossan/.m2/repository/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.jar
Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------
: ExceptionInInitializerError: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @73bb1337
-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

Your version of Java is incompatible with your version of NetBeans because NetBeans 12.2 does not support the use of JDK 17. From the NetBeans 12.2 Release notes Downloading Apache NetBeans 12.2 :

Apache NetBeans 12.2 在 JDK LTS 版本 8 和 11 以及 JDK 15 上运行,即在此 Z69F0F6923BC1F8AAA26B86Z82AFDB 发布时的当前 JDK 版本。

通常,在更改 NetBeans 和/或 Java 的版本时,请确保版本兼容。 这始终记录在 NetBeans 发行说明中。

您有两种选择来解决此问题:

  • 升级到支持 Java 17 的 NetBeans 12.6。
  • 继续使用 NetBeans 12.2,但降级到 Java 15 或更低。 也就是说,将 JDK 15(或更低版本)设为 NetBeans 12.2 的默认平台。

当然,您的项目可能还存在其他问题,但在解决此问题之前,不必担心这些问题。

暂无
暂无

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

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