摘要
在Eclipse中,当我执行“Maven->更新项目配置”时,“Maven Dependencies”会从我的项目的“部署程序集”中删除。
详细信息
我开始使用预配置的Eclipse项目:文件->新建->动态Web项目->JavaServer Face v2.0项目。为了去除"魔法",我将其转换为Maven项目:配置->转换为Maven项目。
pom.xml包含以下内容:
<build>
<finalName>jsf-facelets-tutorial</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WebContent/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.0.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>2.0.5</version>
<scope>runtime</scope>
</dependency>
</dependencies>
为了确保在部署之前将 Maven 依赖项复制到“WEB-INF/lib/”中,我已将它们添加到项目的“Deployment Assembly”中:Project Properties->Deployment Assembly。有关更多详细信息,请参见此问题:Eclipse + Maven + JavaServer Faces -> ClassNotFoundException: StartupServletContextListener。
我知道现在有两个相关的问题。
问题
(1) 当我执行“Project->Maven->Update Project Configuration”时,“Maven Dependencies”会从我的“Deployment Assembly”中删除。是否有一种方法可以阻止这种情况发生,可能是通过某个 Maven 插件?
(2) 当我从 Eclipse 中构建 .war 文件时,一切都很好,在 Tomcat 中运行 .war 文件也很正常。但是当我使用 Maven 从命令行构建 .war 文件 mvn clean compile war:war
时,“WebContent/”中的 .html 文件不会被添加到 .war 文件中。再次,我需要哪些 Maven 设置/插件来解决这个问题?
FYI,这是一个非常基本的应用程序……只有一个登录页面和一个欢迎页面。
如果需要提供任何其他详细信息(web.xml、faces-config-xml、login.xhtml),请告诉我,我会添加它们。
谢谢
--EDIT--
Eclipse 版本:3.6.2
Eclipse m2e 版本:1.0.1
Apache Maven 版本:2.2.1
(1) 解决方案
更新为 Eclipse Java EE 3.7.2 (Indigo)。现在还使用 m2e-wtp Maven Integration for Eclipse WTP plugin
(2) 解决方案
从原型创建新的 Maven 项目,然后使用“Eclipse->导入->现有的 Maven 项目”导入。使用新版本的 Eclipse 和 m2e-wtp,在 Eclipse 中的 Java EE 视图中可以很好地处理标准的 Maven 目录结构
现在 pom.xml 也更简单了:
<build>
<finalName>jsf-facelets-tutorial</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.0.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>2.0.5</version>
<scope>runtime</scope>
</dependency>
</dependencies>