[英]How can I build WAR with Maven in Eclipse?
I have project that I'm now starting as Maven project, but for some reason it is not working. 我有一个项目,我现在开始作为Maven项目,但由于某种原因它不起作用。 Here is my pom.xml: 这是我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProgramName</groupId>
<artifactId>ProgramName</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.core</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
<!-- all other dependecies here -->
</dependencies>
<build>
<finalName>ProgramName</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<webResources>
<resource>
<targetPath>WEB-INF</targetPath>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<includes>
<include>*.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</build>
</project>
Actually, your POM looks a bit weird: 实际上,你的POM看起来有点奇怪:
packaging
for a webapp project. 它缺少webapp项目的正确packaging
。 Here is what a minimal pom looks like: 这是一个最小的pom看起来像:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>my-webapp</finalName>
</build>
</project>
So either modify it and update the project configuration ( right-click on your project then Maven > Update Project Configuration ). 因此,要么修改它并更新项目配置( 右键单击项目,然后单击 Maven>更新项目配置 )。
Or just start over and create your project using the maven-archetype-webapp
. 或者重新开始并使用maven-archetype-webapp
创建项目。 You can do this from Eclipse: New > Project... > Maven Project , then select the maven-archetype-webapp in the wizzard and follow the seps. 您可以从Eclipse中执行此操作: New> Project ...> Maven Project ,然后在wizzard中选择maven-archetype-webapp并按照seps进行操作。
Or from the command line: 或者从命令行:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
for instance, I see 例如,我明白了
<packaging>war</packaging>
missing in your pom, you should have a look at how the maven-war-plugin is used. 你的pom中缺少,你应该看看如何使用maven-war-plugin 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.