61

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 Problem

web.xml is missing and <failOnMissingWebXml> is set to true.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
asmi
  • 621
  • 1
  • 4
  • 6

8 Answers8

95

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>
BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
Michael Ouyang
  • 1,767
  • 1
  • 11
  • 19
18
<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

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Anddy
  • 217
  • 3
  • 6
  • 5
    Please don't post only code as an answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Tyler2P Sep 18 '21 at 18:32
  • 1
    This fixed my problem. I had a lower version (2.2) in my pom. When I updated that to 3.3.1, it got fixed. – Robin Varghese Dec 07 '22 at 19:32
13

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.

Capricorn1
  • 819
  • 9
  • 17
  • can you tell me more about it? my ppm.xml is: ` 4.0.0 com.myclass Elearning 0.0.1-SNAPSHOT war Elearning Website ` – robocon20x Nov 20 '21 at 14:33
  • 1
    My pom.xml file for most of my projects starts off nearly the same: ` 4.0.0 my-artifact-id war Incredible GUI` however, I have a parent pom.xml file with the groupId tag (that uses pom packaging). – Capricorn1 Nov 23 '21 at 13:02
5

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: enter image description here

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>
Darren Parker
  • 1,772
  • 1
  • 20
  • 21
  • I'd like to know what if i need a higher version of Tomcat which is not available in Eclipse ? If I were to configure it via the example in this video https://www.youtube.com/watch?v=xsfRSrDgBWI, will it be possible to remove the Tomcat later to make it flexible for deployment in other kinds of servers ? – Karen Goh Feb 27 '23 at 04:02
2

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>
  • After update Maven Project

enter image description here

Sagar R G
  • 29
  • 1
1

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

Lova Chittumuri
  • 2,994
  • 1
  • 30
  • 33
-1

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

YourHelper
  • 703
  • 7
  • 17
Syed Umar
  • 9
  • 1
-3

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.

ouflak
  • 2,458
  • 10
  • 44
  • 49