Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 333824

Summary: Adding Maven Dependencies to Deployment Assembly for webapp causes "provided" jars to appear in war file.
Product: z_Archived Reporter: apfryer
Component: m2eAssignee: Project Inbox <m2e.core-inbox>
Status: CLOSED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: fbricon, hanriseldon, igor, rocky_mm
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description apfryer CLA 2011-01-09 23:05:50 EST
Build Identifier: 20100917-0705

In eclipse I have a dynamic web project and use maven (m2e) to manage dependencies.  One dependency that I use is the javaee-api which is always provided by the server I deploy to.  I include this dependency in the pom.xml with a scope of "provided".

When I build the war file using maven, the javaee-api jar file is NOT included in the war which is the expected behavior.  The problem occurs when building the war file with eclipse (file->export).  When I configure the Deployment Assembly to include the Maven Dependencies (which is required), when eclipse builds the WAR it includes ALL jars in the maven pom.xml regardless of the scope.  It should NOT include jars with a scope of provided, test and others.

Reproducible: Always

Steps to Reproduce:
1. create a dynamic web project and use maven to manage dependecies
2. add a dependency to the javaee-api with a scope of provided
3. In the Deployment Assembly, add 'Java Build Path Entries'->'Maven Dependencies'.
4. Export the war file and open it.  Inside it you'll see the WEB-INF/lib/javaee-api.jar file which shouldn't be there because it has a maven scope of provided.
Comment 1 Fred Bricon CLA 2011-01-30 19:43:37 EST
You SHOULD NOT do step 3, because you basically tell WTP to deploy all maven dependencies, regardless of their scope.

Any change to the project dependencies is automatically handled by the m2eclipse-wtp configurator, so you don't have to do anything, seriously. 

Your real problem is you probably didn't specify the war packaging, when asking maven to manadependencies
Comment 2 Fred Bricon CLA 2011-01-30 19:51:09 EST
...accidentaly hit enter too soon on last comment, sorry.

so, you need to set the packaging to war in your pom.xml, and since your project probably uses eclipse's convention -your web resources sitting in /WebContent-, you should either move them to src/main/webapp or configure your maven war plugin :

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

After changing the packaging type or the maven-war-plugin configuration, you'll need to run Maven Update Configuration.

Finally, be aware that any WTP related issues should be opened at https://issues.sonatype.org/browse/MECLIPSEWTP
Comment 3 apfryer CLA 2011-01-31 00:37:59 EST
Thanks for your comments.  

In response, I already DID have the war packaging specified and am using the standard maven directory layout for a web app (ie. src/main/java/webapp ).  

Following your advice, I removed "Maven Dependencies" from the "Deployment Assembly" for my web app and recreated the war file using eclipse (wtp).  Unfortunately none of the jar files specified in my pom.xml are included in the generated war file.  

I'm wondering if i have something configured incorrectly if you're so sure that the jar file dependencies SHOULD appear in the wtp created war file.  If so, then I'm not seeing that and perhaps should raise a bug for that issue?

I don't know if this is an eclipse wtp issue, m2e issue or user issue.  You might also wonder why I want to build via wtp.  The reason is so I can quickly test code changes and run them in a tomcat server setup inside eclipse.  This requires the eclipse build of the war file to get the jar file dependencies correct.  I suspect this would be a common feature alot of developers would want.

I'm using Eclipse Helios with "Maven Integration for Eclipse" 0.12.0.20101115-1102.

My pom.xml is below...

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.pokersquid</groupId>
    <artifactId>leaguemanager</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>leaguemanager Web App</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
        	<groupId>org.apache.openejb</groupId>
        	<artifactId>javaee-api</artifactId>
        	<version>6.0-SNAPSHOT</version>
        	<type>jar</type>
        	<scope>provided</scope>
        </dependency>
        <dependency>
        	<groupId>com.pokersquid.leaguemanager</groupId>
        	<artifactId>poker-entities</artifactId>
        	<version>0.0.1-SNAPSHOT</version>
        	<type>jar</type>
        	<scope>compile</scope>
        </dependency>
        <dependency>
        	<groupId>com.pokersquid</groupId>
        	<artifactId>poker-ejbs</artifactId>
        	<version>0.0.1-SNAPSHOT</version>
        	<type>jar</type>
        	<scope>compile</scope>
        </dependency>
        
 
        <dependency>
        	<groupId>javax.servlet</groupId>
        	<artifactId>jstl</artifactId>
        	<version>1.2</version>
        	<type>jar</type>
        	<scope>compile</scope>
        </dependency>
        
        <dependency>
        	<groupId>commons-beanutils</groupId>
        	<artifactId>commons-beanutils</artifactId>
        	<version>1.8.3</version>
        	<type>jar</type>
        	<scope>compile</scope>
        </dependency>
        
        <dependency>
		  <groupId>org.freemarker</groupId>
		  <artifactId>freemarker</artifactId>
		  <!-- Latest 2.3.x (not 2.4.x), at least 2.3.16 -->
		  <version>[2.3.16,2.4)</version>
		</dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
        <finalName>leaguemanager</finalName>
    </build>
    
    <repositories>
    <repository>
      <id>maven2-repository.dev.java.net</id>
      <name>Java.net Repository for Maven</name>
      <url>http://download.java.net/maven/2</url>
    </repository>
    </repositories>

</project>
Comment 4 Igor Fedorenko CLA 2011-03-12 12:50:32 EST
Given that m2e/wtp integration is not part of m2e, I am tempted to close this bug as NOT_ECLIPSE and create corresponding issue under https://issues.sonatype.org/browse/MECLIPSEWTP. Any objections?
Comment 5 Rade Martinović CLA 2011-03-21 13:51:05 EDT
I can confirm this bug.

If you are to close this bug and open a new one please provide link to new bug report.

Thank you!
Comment 6 Rade Martinović CLA 2011-03-21 14:27:38 EDT
After searching carefully for any related bugs in m2e/wtp integration issue tracker I have encountered and issue report that resolved my problem:

https://issues.sonatype.org/browse/MNGECLIPSE-714

Basically, what resolves the problem is the installation of WTP integration plug-in, which takes care of exporting dependencies.
Comment 7 Eugen Paraschiv CLA 2011-03-21 14:37:35 EDT
I did manage to solve it like that, but isn't the problem the fact that Maven isn't managing the dependencies itself? I assumed what I did was a workaround, not the solution.
Comment 8 Rade Martinović CLA 2011-03-22 06:15:38 EDT
I assume that WTP projects need special care when mavenized, hence the existence of the Maven WTP plugin.
Comment 9 Igor Fedorenko CLA 2011-03-22 11:51:47 EDT
m2e-wtp and related bugs should be filed in https://issues.sonatype.org/browse/MECLIPSEWTP
Comment 10 Denis Roy CLA 2021-04-19 13:27:23 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/