首页 文章

Eclipse Maven动态Web项目 - > Maven覆盖部署程序集

提问于
浏览
17

Summary

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

Details

我从一个预配置的Eclipse项目开始:File-> New-> Dynamic Web Project-> JavaServer Face v2.0 Project . 为了删除“魔法”,我将其转换为Maven项目:Configure-> Convert to Maven project .

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 .

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

Problems

(1) 当我"Project->Maven->Update Project Configuration"时,"Maven Dependencies"从我的"Deployment Assembly"中删除 . 有没有办法阻止这种情况发生,可能是通过一些Maven插件?

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

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

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

谢谢

--EDIT--

Eclipse版本:3.6.2

Eclipse m2e版本:1.0.1

Apache Maven版本:2.2.1

(1) Solution

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

(2) Solution

archetype创建新的Maven项目,然后是Eclipse-> Import-> Existing Maven Project . 使用新的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>

1 回答

  • 4

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

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

    另见:Maven/Tomcat Projects In Eclipse Indigo/3.7

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

相关问题