错误注入:org.apache.maven.plugin.war.WarMojo

Zar*_*cor 6 java netbeans maven

控制台打印的内容,我正在尝试在 netbeans 上运行 Java Web 应用程序,但我不太明白为什么它会给我这个错误。

Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/xstream/xstream/1.4.4/xstream-1.4.4.jar (483 kB at 33 kB/s)
Error injecting: org.apache.maven.plugin.war.WarMojo
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.ExceptionInInitializerError
  at org.apache.maven.plugin.war.WarMojo.<init>(Unknown Source)
  while locating org.apache.maven.plugin.war.WarMojo

1 error
    at com.google.inject.internal.InternalProvisionException.toProvisionException (InternalProvisionException.java:226)
    at com.google.inject.internal.InjectorImpl$1.get (InjectorImpl.java:1053)
    at com.google.inject.internal.InjectorImpl.getInstance (InjectorImpl.java:1086)
    at org.eclipse.sisu.space.AbstractDeferredClass.get (AbstractDeferredClass.java:48)
    at com.google.inject.internal.ProviderInternalFactory.provision (ProviderInternalFactory.java:85)
Run Code Online (Sandbox Code Playgroud)

无法在项目primera_web上执行目标org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war): 执行目标org.apache.maven.plugins:maven-war-plugin的默认战争: 2.3:war failed: 由于 API 不兼容,无法在插件 'org.apache.maven.plugins:maven-war-plugin:2.3' 中加载 mojo 'war':org.codehaus.plexus.component.repository.exception .ComponentLookupException: 空

realm =    plugin>org.apache.maven.plugins:maven-war-plugin:2.3
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/HP/.m2/repository/org/apache/maven/plugins/maven-war-plugin/2.3/maven-war-plugin-2.3.jar
urls[1] = file:/C:/Users/HP/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar
urls[2] = file:/C:/Users/HP/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar
urls[3] = file:/C:/Users/HP/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.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 @5c82031b
-> [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
Run Code Online (Sandbox Code Playgroud)

文件 pom.xml

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

    <groupId>com.mycompany</groupId>
    <artifactId>primera_web</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>primera_web</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</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.7</source>
                    <target>1.7</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-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

解决问题的建议??

小智 8

从 JDK 1.8 升级到 JDK 17 后,我遇到了同样的问题,我通过升级插件版本解决了这个问题。

前:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
</plugin>
Run Code Online (Sandbox Code Playgroud)

后:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.1</version>
</plugin>
Run Code Online (Sandbox Code Playgroud)


小智 6

我有同样的问题。我正在使用 Eclipse 2021 年 6 月版。在 POM.xml 中手动配置最近的战争插件之一后,问题得到解决。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.1</version>
</plugin>
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考,[当前版本](https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-war-plugin) 是 3.3.2。 (4认同)

Vid*_*idz 5

在 POM.xml 中手动配置 war 插件然后进行全新安装后,我的问题得到解决

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.1</version>
</plugin>
Run Code Online (Sandbox Code Playgroud)

然后在终端中进行全新安装,如下所示:

mvn clean install
Run Code Online (Sandbox Code Playgroud)

这应该为您提供 war 文件 (javaj22ee.war) 状态,例如:

[INFO] Building war: /Users/my_proj/java/javaj2ee/target/javaj2ee.war
[INFO]
[INFO] --- install:3.1.1:install (default-install) @ javaj2ee ---
[INFO] Installing /Users/my_proj/java/javaj2ee/pom.xml to 
/Users/.m2/repository/org/example/javaj2ee/1.0-SNAPSHOT/javaj2ee-1.0- 
SNAPSHOT.pom
[INFO] Installing /Users/my_proj/java/javaj2ee/target/javaj2ee.war to 
/Users/.m2/repository/org/example/javaj2ee/1.0-SNAPSHOT/javaj2ee-1.0- 
SNAPSHOT.war
[INFO] -----------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------------------- 
[INFO] Total time:  8.506 s
[INFO] Finished at: 2023-09-04T18:37:31+05:30
[INFO] ----------------------------------------------------------------- 
Run Code Online (Sandbox Code Playgroud)


Phi*_*lip 1

您可以通过将项目中的 JDK 更改为 JDK 14 来修复此问题。左键单击您的项目并转到“属性”->“构建”->“编译”。将 JDK 更改为版本 14。如果您没有 JDK 14,可以通过单击“管理 Java 平台”来管理它。JDK的下载在这里