When I am creating a Maven project I am getting this error in pom.xml
Could not initialize class org.apache.maven.plugin.war.util.WebappStructureSerializer
-Maven Configuration Problemweb.xml is missing and <failOnMissingWebXml> is set to true.
When I am creating a Maven project I am getting this error in pom.xml
Could not initialize class org.apache.maven.plugin.war.util.WebappStructureSerializer
-Maven Configuration Problemweb.xml is missing and <failOnMissingWebXml> is set to true.
It might because the version of maven-war-plugin
is too old in your project.
Try to add below code in your pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>
</build>
</project>
Note: you should have the build tag place everything inside build tag then, it will not throw error
If you are getting this error within Eclipse (my Eclipse version was Version: 2021-09 (4.21.0), Build id: 20210910-1417
at the time of writing) and you recently tried to move to JDK 17, it appears Eclipse is not compatible with JDK 17. It requires at least JDK 11. I reverted back to Java 11.0.12 and the error has gone away.
I'm using Windows 10 and Eclipse Version: 2022-03 (4.23.0) Build id: 20220310-1457
My project uses JDK8, but newer versions of Eclipse require at least JDK11.
I configure this using Window->Preferences->Java->Installed JREs
as shown in the screenshot:
Maven from windows cmd shell works fine: mvn clean package
But, Eclipse gives an error on my pom.xml: Could not initialize class org.apache.maven.plugins.war.util.WebappStructureSerializer
For reference, Eclipse gave some other error messages while I was attempting to fix the issue, such as this one: 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
This error seems to be some compatibility issue with maven-war-plugin and the JDK17 that eclipse runs under. It's probably due to the 'module' permissions.
Using these helpful answers, I was able to find a workaround:
@Capricorn1 https://stackoverflow.com/a/69544567/4505142
@SreedharGS https://stackoverflow.com/a/29383652/4505142
I downloaded OpenJDK11 from: https://adoptium.net/
Updated eclipse.ini to use JDK11 instead of JDK17:
--launcher.appendVmargs
-vm
C:\Users\User1\OpenJDK11\jdk-11.0.15+10\bin
-vmargs
-Dosgi.requiredJavaVersion=11
-Dosgi.instance.area.default=@user.home/eclipse-workspace
-Dsun.java.command=Eclipse
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dosgi.requiredJavaVersion=11
-Dosgi.dataAreaRequiresExplicitInit=true
-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true
-Xms512m
-Xmx1024m
--add-modules=ALL-SYSTEM
For reference, here's the original eclipse.ini JDK17 path:
-vm
plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.2.v20220201-1208/jre/bin
Using JDK11 to run Eclipse, eliminated the pom.xml error "Could not initialize class org.apache.maven.plugins.war.util.WebappStructureSerializer"
For reference, here are the relevant snippets of my pom.xml:
<properties>
<spring-boot.version>1.5.13.RELEASE</spring-boot.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<packagingExcludes>**/application-*.properties</packagingExcludes>
</configuration>
<executions>
<execution>
<id>default-war</id>
<phase>prepare-package</phase>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
In Pom.xml, need to add the below snippet, and please find image attachment
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>
</build>
Please use the below code snip:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</pluginManagement>
Please refer this
Try to add the plugin to your maven project, by adding this in your pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
After that: Right click -> Maven -> Update Project
I have the same problem as this when I create a maven project. So I got a solution for this just adding this plug into your pom.xml:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
If you already have it, then you should upgrade its version.