Eclipse + Maven + 动态 Web 项目 ->Maven 覆盖部署程序集 [英] Eclipse + Maven + Dynamic Web Project -> Maven overwrites Deployment Assembly

查看:36
本文介绍了Eclipse + Maven + 动态 Web 项目 ->Maven 覆盖部署程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总结

在 Eclipse 中,当我Maven->更新项目配置"时,Maven 依赖项"从我的项目的部署程序集"中删除.

In Eclipse, when I "Maven->Update Project Configuration" "Maven Dependencies" gets removed from the "Deployment Assembly" of my project.

详情

我从一个预先配置好的 Eclipse 项目开始:File->New->Dynamic Web Project->JavaServer Face v2.0 Project.为了移除魔法",我将其转换为 Maven 项目:配置->转换为 Maven 项目.

I started with a pre-configured Eclipse project: File->New->Dynamic Web Project->JavaServer Face v2.0 Project. To remove the "magic" I then converted it to a Maven project: Configure->Convert to Maven project.

pom.xml 包含以下内容:

pom.xml contains the following:

<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/",我将它们添加到项目的部署程序集":项目属性->部署程序集.有关更多详细信息,请参阅此问题:Eclipse + Maven + JavaServer Faces ->ClassNotFoundException: StartupServletContextListener.

Then, to make sure the Maven dependencies are copied to "WEB-INF/lib/" before deploying, I added them to the project's "Deployment Assembly": Project Properties->Deployment Assembly. For more details, see this question: Eclipse + Maven + JavaServer Faces -> ClassNotFoundException: StartupServletContextListener.

我知道有两个相关的问题.

I know have two related problems.

问题

(1) 当我项目->Maven->更新项目配置"时,Maven 依赖项"从我的部署程序集"中删除.有没有办法阻止这种情况发生,可能是通过一些 Maven 插件?

(1) When I "Project->Maven->Update Project Configuration", "Maven Dependencies" gets removed from my "Deployment Assembly". Is there a way to stop this from happening, possibly via some Maven plugin?

(2) 当我从 Eclipse 中构建 .war 时一切正常,.war 在 Tomcat 中运行良好.但是当我使用 Maven 从命令行构建它时,mvn clean compile war:war,来自WebContent/"的 .html 文件不会添加到 .war 中.同样,我需要哪些 Maven 设置/插件来解决这个问题?

(2) When I build the .war from within Eclipse everything is fine, the .war runs fine in Tomcat. But when I build it from command line with Maven, mvn clean compile war:war, the .html files from "WebContent/" is not added to the .war. Again, Which Maven settings/plugins do I need to remedy this?

仅供参考,这是一个非常基本的应用程序...只是一个登录页面和一个欢迎页面.

FYI, it's a very basic application... just a login page and a welcome page.

如果我需要提供任何其他详细信息(web.xml、faces-config-xml、login.xhtml),请告诉我,我会添加它们.

If there are any additional details I should provide (web.xml, faces-config-xml, login.xhtml), let me know and I'll add them.

谢谢

--编辑--

Eclipse 版本:3.6.2

Eclipse version: 3.6.2

Eclipse m2e 版本:1.0.1

Eclipse m2e version: 1.0.1

Apache Maven 版本:2.2.1

Apache Maven version: 2.2.1

(1) 解决方案

更新到 Eclipse Java EE 3.7.2 (Indigo).现在还使用 m2e-wtp Maven Integration for Eclipse WTP 插件

Updated to Eclipse Java EE 3.7.2 (Indigo). Now also using m2e-wtp Maven Integration for Eclipse WTP plugin

(2) 解决方案

archetype,然后Eclipse->Import->Existing Maven Project.使用新的 Eclipse 版本和 m2e-wtp,Eclipse 中的 Java EE 透视图可以很好地与标准 Maven 目录结构配合使用

Created new Maven project from archetype, then Eclipse->Import->Existing Maven Project. With new Eclipse version and the m2e-wtp, the Java EE perspective in Eclipse works well with the standard Maven directory structure

pom.xml 现在也更简单了:

The pom.xml is now simpler too:

<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>

推荐答案

我建议迁移到 Eclipse 3.7.x (Indigo),它对 m2e 有更好的支持,并且还允许您使用 WTP 的 Maven 集成(单独安装),这应该会让事情变得更容易.我想你的大部分问题应该通过更新到 Indigo 来解决.

I would recommend to move to Eclipse 3.7.x (Indigo), which has better support for m2e, and also allows you to use the Maven Integration for WTP (separate install), which should make things a lot easier. I guess most of your problems should be solved by updating to Indigo.

安装链接:http://marketplace.eclipse.org/node/96737

另见此处:Eclipse Indigo/3.7 中的 Maven/Tomcat 项目

编辑将您的网络资源放在 WebContent 下,然后将其作为目录添加到 WAR 插件中可能是一个解决方案.干净的方法是将它们放在 src/main/resourcessrc/main/webapp 下,它们应该自动包含在 WAR 文件中.WebContent 不是 Maven 的标准目录之一.

Edit Putting your web resources under WebContent and then adding that as a directory in the WAR plugin may be a solution. The clean way would be to have them under src/main/resources or src/main/webapp and they should be included automatically in the WAR file. WebContent is not one of Maven's standard directories.

这篇关于Eclipse + Maven + 动态 Web 项目 ->Maven 覆盖部署程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆