u123
u123

Reputation: 16329

maven-war-plugin and the Spring JavaConfig

I am replacing my web.xml and servlet.xml files using JavaConfig based on: http://javahash.com/spring-4-mvc-hello-world-tutorial-full-example/

As suggested in the comments I am also trying to follow the solution proposed in: Why is maven-war-plugin failing for web.xml missing if I configured it not to fail on missing web.xml?

but it does not fix my issue, see below.

But after I have replaced those files (added the corresponding *.java files and deleted the old *.xml files) I get this error from the maven-war-plugin:

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

I have then added:

        <failOnMissingWebXml>false</failOnMissingWebXml>

to the configuration, below the plugin configuration

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <executions>
            <execution>
                <id>default-war</id>
    <phase>prepare-package</phase>                      
                <configuration>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <archive>
      <manifest>
        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
      </manifest>
      <manifestEntries>
        <Implementation-Build>${buildNumber}</Implementation-Build>
      </manifestEntries>
    </archive>
                    <webResources>
                        <resource>
                            <directory>${basedir}/src/main/webapp</directory>
                            <filtering>true</filtering>
                            <includes>
                                <include>**/*.jsp</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </execution>
        </executions>
    </plugin>

but I get this error in eclipse:

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

and when I build I get:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.0.2:war (default-war) on project webapp-module: Error assembling WAR: Deployment descriptor: /home/user/workspace_j2ee/webapp/webapp-module/target/webapp-module/WEB-INF/web.xml does not exist. -> [Help 1]
[ERROR] 

If I just add a minimal web.xml like:

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Spring MVC Application</display-name>

</web-app>

I can build the project using maven but I get this error in eclipse:

org.eclipse.jst.j2ee.commonarchivecore.internal.exception.DeploymentDescriptorLoadException: WEB-INF/web.xml
Stack trace of nested exception:
org.eclipse.jst.j2ee.commonarchivecore.internal.exception.EmptyResourceException: platform:/resource/webapp-module/target/m2e-wtp/web-resources/WEB-INF/web.xml
    at org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil.getRoot(ArchiveUtil.java:439)
    at org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.XmlBasedImportStrategyImpl.primLoadDeploymentDescriptor(XmlBasedImportStrategyImpl.java:42)
    at org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.War22ImportStrategyImpl.loadDeploymentDescriptor(War22ImportStrategyImpl.java:90)
    at org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.War22ImportStrategyImpl.importMetaData(War22ImportStrategyImpl.java:84)
    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.WARFileImpl.getDeploymentDescriptor(WARFileImpl.java:146)
    at org.eclipse.jst.j2ee.model.internal.validation.WarValidator.validateInJob(WarValidator.java:334)
    at org.eclipse.jst.j2ee.internal.web.validation.UIWarValidator.validateInJob(UIWarValidator.java:113)
    at org.eclipse.wst.validation.internal.operations.ValidatorJob.run(ValidatorJob.java:78)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Is the point of JavaConfig not that you should be able to replace those files?

It seems that the web.xml file is completely removed in this example:

http://kielczewski.eu/2013/11/spring-mvc-without-web-xml-using-webapplicationinitializer/

Upvotes: 1

Views: 1200

Answers (1)

inigo skimmer
inigo skimmer

Reputation: 918

It seems like you have rather old version of plugin

maven-war-plugin:2.0.2

But according to this page

http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#failOnMissingWebXml

failOnMissingWebXml is introduced since 2.1.x version.

Try to use more up to date version.

Upvotes: 1

Related Questions