Eclipse + Maven + Dynamic Web Project -> Maven overwrites Deployment Assembly
Asked Answered
G

1

18

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>
Galanti answered 2/4, 2012 at 12:3 Comment(3)
Which version of Eclipse and M2Eclipse are you using?Bogan
Eclipse version: 3.6.2 Eclipse m2e version: 1.0.1 Apache Maven version: 2.2.1Galanti
I have updated my answer to address your question regarding the WebContent directory.Bogan
B
4

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.

Bogan answered 2/4, 2012 at 12:35 Comment(10)
Thanks, will try out and get back to you when I'm done (will take a bit of time to download & install everything, then start new project). One question, with the "m2eclipse-wtp" plugin, will I still need to use build-helper-maven-plugin (Maven plugin) & m2e-build-helper-connector (Eclipse)?Galanti
Installed now. With this new configuration, what method of creating a project do you recommend? command line maven from archetype, or using Eclipse wizard?Galanti
I always create a small basic POM, either by copying from another project, or by using the archetype wizard from within Eclipse.Bogan
with the new structure I know see this... in Web Deployment Assembly I see 4 entries. ((1)) /src/main/java -> WEB-INF/classes [OK] ((2)) /src/main/webapp -> / [.html, web.xml, etc.?] ((3)) Maven Dependencies -> WEB-INF/lib [OK] ((4)) /target/m2e-wtp/web-resources -> / [what is this for?]Galanti
when working on a WTP project with the m2e and m2e-wtp plugins, do the Faces Config Editor still open? Mine no longer does, and I've been unable find out why (#9993477)Galanti
I haven't used this editor so far, but a quick test shows that I can open a faces-config.xml file fine with it.Bogan
did you just use "Open With..."->"Faces Config Editor"?Galanti
ok it was a dumb mistake. i didn't add JavaServer Faces facet my project because it broke my build, but now I see I just had to remove the Eclipse-added JSF library from my build path... everything fine nowGalanti
That "src/main/webapp" hint helped me understand what I was doing wrong. Thanks.Soph
It is a old subject, but i have exactly the same pb with Eclipse Mars. So what to do ? :pBrownstone

© 2022 - 2024 — McMap. All rights reserved.