我更换使用JavaConfig我的web.xml和servlet.xml中文件依据: http://javahash.com/spring-4-mvc-hello-world-tutorial-full-example/Maven的战争插件和Spring JavaConfig
由于建议的意见,我也试图遵循以下提出的解决方案: Why is maven-war-plugin failing for web.xml missing if I configured it not to fail on missing web.xml?
但它不能解决我的问题,请参阅下文。
但我已经取代了这些文件后(加入相应的* .java文件,并删除了旧的* .xml文件)我从Maven的战争插件得到这个错误:
web.xml is missing and <failOnMissingWebXml> is set to true
我已经然后加入:
<failOnMissingWebXml>false</failOnMissingWebXml>
上述结构,插件配置下面
<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>
但我得到这个错误在日食:
web.xml is missing and <failOnMissingWebXml> is set to true
,当我建立我得到:
[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]
如果我只需要添加一个最小的的web.xml,如:
<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>
我可以使用maven构建项目,但是我在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)
点是JavaConfig不是你应该能够替换这些文件吗?
看来,的web.xml文件在这个例子中完全移除:
http://kielczewski.eu/2013/11/spring-mvc-without-web-xml-using-webapplicationinitializer/
可能的重复[为什么maven-war-plugin失败,如果我配置它不会失败web.xml缺少web.xml?](http:// stackoverflow。com/questions/24291299/why-is-maven-war-plugin-failing-for-web-xml-missing-if-i-configured-it-to-fa) –
我看过那篇文章,但是我当我应用答案中提出的更改时,仍然会从maven和eclipse中获得错误 – u123