Why is maven-war-plugin failing for web.xml missing if I configured it not to fail on missing web.xml?

后端 未结 3 388
南方客
南方客 2021-01-12 02:50

Here\'s a challenge: why is this build failing?

I have configured Maven\'s maven-war-plugin not to fail on an abscent web.xml file, it seems:

    <         


        
相关标签:
3条回答
  • 2021-01-12 03:19

    The problem is related to the version that you are currently working with. You need to see your local repository and see the version that you have already downloaded. Go to your .m2 folder and look for

    .m2\repository\org\apache\maven\plugins\maven-compiler-plugin
    

    In that folder you can see the versions that are available for you.

    Change the version for the version that you have in your folder and it works!

    0 讨论(0)
  • 2021-01-12 03:27

    The execution ID in the POM is prepare-war. Maven runs its own default execution of the war plugin for projects with packing type war. The default execution has ID default-war. As the POM is currently configured, the war goal is running twice.

    If you look at the error message:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.4:war (default-war) on project com.specktro.orchid.operations.portal.frontend: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
    

    You may see the execution ID that fails in parenthesis (default-war). If you change the execution ID to default-war your problem will go away, AND you will no longer have two executions of the war goal running.

    0 讨论(0)
  • 2021-01-12 03:30

    This should work:

    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare-war</id>
                        <phase>prepare-package</phase>
                        <configuration>
                            <archiveClasses>false</archiveClasses>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                    <classpathPrefix />
                                </manifest>
                                <manifestEntries>
                                    <Implementation-Build>${build.number}</Implementation-Build>
                                    <Implementation-Title>${project.name}</Implementation-Title>
                                    <Built-By>${user.name}</Built-By>
                                    <Built-OS>${os.name}</Built-OS>
                                    <Build-Date>${build.date}</Build-Date>
                                </manifestEntries>
                            </archive>
                            <webResources>
                                <resource>
                                    <!-- this is relative to the pom.xml directory -->
                                    <directory>./target/dist</directory>
                                </resource>
                            </webResources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    Please notice that the <failOnMissingWebXml>false</failOnMissingWebXml> section has been moved up to the plugin configuration rather than the execution.

    0 讨论(0)
提交回复
热议问题