且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-17 19:53:16

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



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



另请参见: Eclipse中的Maven / Tomcat项目Indigo / 3.7



编辑
将您的Web资源放在 WebContent 之前,然后将其添加为WAR插件中的目录可能是一个解决方案。干净的方式是让他们在 src / main / resources src / main / webapp 之下,他们应该自动包含在WAR文件中。 WebContent 不是Maven的标准目录之一。


Summary

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

Details

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

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.

Problems

(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) 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.

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

Thanks

--EDIT--

Eclipse version: 3.6.2

Eclipse m2e version: 1.0.1

Apache Maven version: 2.2.1

(1) Solution

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

(2) Solution

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

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>

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.

Install Link: http://marketplace.eclipse.org/node/96737

Also see here: Maven/Tomcat Projects In Eclipse Indigo/3.7

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.