Maven错误无法访问属性的默认字段
我使用的是最新版本的JAVA-&>16。当我运行MVN CLEAN时,收到无法初始化类org.apache.maven.plugin.war.util.WebappStructureSerializer错误。我读到添加maven-war-plugin可能是一种解决方案,但它对我不起作用。当我运行MVN安装时,出现以下错误:
注入构造函数时出错,java.lang.ExceptionInInitializerError: 无法访问位于的属性的默认字段 (来源不详) 查找org.apache.maven.plugin.war.WarMojo
如何解决这些问题?它们是由Java版本引起的吗?
<modelVersion>4.0.0</modelVersion>
<groupId>web-programming</groupId>
<artifactId>servlet-demo</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>16</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Optional. Allows the app to be run by simply typing mvn jetty:run -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.4</version>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
</dependency>
</dependencies>
<configuration>
<contextPath>/</contextPath>
<scanIntervalSeconds>10</scanIntervalSeconds>
<connectors>
<connector
implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9090</port>
</connector>
</connectors>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
jdk
更改pom.xml
中的WAR插件版本,并根据您的推荐答案版本添加maven-compiler-plugin
。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
相关文章