WTP - m2e not deploying transitive dependencies - eclipse

I have a web application which is structured in this way:
A.jar -> B.war -> C.war
I'm using Eclipse Juno and the WTP version is 1.1. The A.jar is a workspace utility project which is being included by B.war. B.war is a war project that is included by C.war as an overlay. That's the way I'm doing that:
<dependency>
<groupId>com.projects</groupId>
<artifactId>B</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
After that, I deploy the C project to the Tomcat server. That works like a charm if I manually deploy the Maven generated war to the Tomcat, because A.jar is included in WEB-INF/lib. However my problem comes when I let m2e-wtp do the deploy, because it's doing the overlay properly but not including the A transitive dependency. I tried including it as a pom, as I read somewhere around here, but I have the same result.
<dependency>
<groupId>com.projects</groupId>
<artifactId>B</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.projects</groupId>
<artifactId>B</artifactId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
I'm using the newest versions of m2e (1.2) and m2e-wtp (0.16) and have my projects updated with the Maven configuration.
Is it an m2e-wtp issue or simply do I have to organize my project in other way?
EDITED
I noticed m2e-wtp configuration is stored into Eclipse's project./settings/org.eclipse.wst.common.component file. That's how it looks for my war:
<dependent-module deploy-path="/"
handle="module:/overlay/prj/B?includes=**/**&excludes=META-INF/MANIFEST.MF">
<dependency-type>consumes</dependency-type>
</dependent-module>
<dependent-module deploy-path="/"
handle="module:/overlay/slf/?includes=**/**&excludes=META-INF/MANIFEST.MF">
<dependency-type>consumes</dependency-type>
</dependent-module>
As I can see the war dependency is set for consume while the jar dependencies are set for use.
Released m2e-wtp version 0.17 doesn't seem to fix it.
EDITED (2013-08-30)
Today I was back to the same problem. Even I have Eclipse kepler installed with the latest stable release of WTP out of the box, this problem seems to persist. I thought it was solved, but I apparently mischeck it...

I think it is not a problem of your project organization. Your issue is very similar to this m2e-wtp bug report.

It seems to be a Eclipse Juno and WTP Plugin problem.
I had the same problem and i solved in this way:
Backup your eclipse workspace and your project code
remove your project from eclipse (without remove the contents)
open a command terminal (cmd)
run mvn eclipse:clean
run mvn eclipse:eclipse -Dwtpversion=2.0
edit your eclipse classpath file with a text editor: %PROJECT_PATH%\.classpath
remove all lines with attribute kind="var" from your .classpath file. For example:
< classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar" sourcepath="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5-sources.jar"/>
save file & close editor.
in eclipse, click on: file->Import...->Maven->import existing maven project, and import your project again
Maven -> Update Project (if you want)
You could see on deployment assembly in eclipse project properties that problem is solved and the maven dependencies are there.
Hope this helps.

I also have this problem. I have an ugly workaround:
Put all the original war's dependencies in a separate project (type jar) and make both original war and overlay war depend on that. So for the example:
A.jar -> B.war -> C.war
becomes
A.jar -> B-dependencies.jar (new module called B-dependencies created)
B-dependencies.jar -> B.war
B-dependencies.jar -> C.war
Note that it's not specific to Tomcat; I'm using JBoss.

Related

How to move jar file in Maven Library

I am using Eclipse Indigo with Maven. i have created Maven Project and selected ArtifactId as webapp-archetype 1.5.1 as shown in the screen shot below.
When i am done completing the project, list of libraries appears under Maven Library. Now, i want to add few external Jars to Maven Library by going into its build-Path and add external jar, it adds the jar file but NOT under Maven Library. I can't manually move it under Maven Library, neither can i paste it.
P.S , i want to remove few jar files from the Maven Library as well.
You need to add dependencies in your pom.xml not by adding external jars manually to your build path.
So remove the extra jar you added by hand end add:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>
Edit
If you have m2eclipse plugin installed on your eclipse, right click on your project, and under Maven menu do a "Update project configuration".
Your new jar should be displayed under Maven dependencies
or if not, run a mvn eclipse:clean eclipse:eclipse to regenerate the .project and .classpath of your project

eclipse buildpath error with maven dependency

In my pom.xml i have the following dependency
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
<version>3.2.8</version>
</dependency>
My eclipse download the jar file as expected and my code compiles just fine. But when i execute my JUnit tests i'm gettin a exception wich is the cenario expected for when the dependency is missing.
If i change the dependency to
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
<version>3.2.8</version>
<scope>system</scope>
<systemPath>\path\to\wstx-asl-3.2.8.jar</systemPath>
</dependency>
the issue persists. But when i remove the dependency from the pom.xml and add it to the builpath using the standard eclipse way everything works just fine.
Executing a mvn package the tests are executed just fine. Only when i run them in the eclipse envirionment that the issue occurs.
what am i missing here?
Eclipse has a separate build path. When using maven projects within Eclipse you need to rebuild the build path that Eclipse uses to point to the downloaded Maven artifacts.
You do this by running mvn eclipse:eclipse on your project and then clean and build your project from within eclipse.
This Maven plugin rebuilds your .classpath file within your project, this file stores your build path.
See: http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html

Eclipse Maven Dependency

I have just added dependencies to an eclipse project so that my jar can see other jars. How can I be sure that the dependencies work, and that what I've done is correct? I view a pom.xml file that has been created so what are the target folder and classes,test-classes subfolders used for? Thanks
If you have the m2eclipse plugin installed you can open your pom in Eclipse and click on the Dependency Hierarchy tab to view your resolved dependencies. You should manage all dependencies through Maven with the setup you are describing.
If you want to check command line you may want to look at using Effective Pom.
If you use m2e, it adds Maven Dependencies pseudo library to your project.
You may expand it and see if the dependent jar file is in there.
If it is, Eclipse ( or more precisely m2e ) has resolved the dependency correctly and it's available for you project build.
If you added your dependencies correctly your application should build and execute correctly, or am I missing something? Dependencies should be added to a POM section that looks like this example:
<dependencies>
<dependency>
<groupId>annogen</groupId>
<artifactId>annogen</artifactId>
<version>0.1.0</version>
</dependency>
<!-- other dependencies here -->
</dependencies>
Maven and the m2e/m2eclipse plugin rely on source files to be conventionally placed in src/main/java for application code and src/test/java for test code. Application code is compiled to target/classes and test code is compiled to target/test-classes. If you plan to use Maven and/or m2e/m2eclipse, do read about it. Maven: The Complete Reference is a good starting point.

Eclipse Project with Dependency Management by Maven

I have a Eclipse project where Maven manages the dependencies. I have also few jar files that are not Maven enable and I locate them at src/main/webapp/WEB-INF/lib. I have no issue to build/run the project in Eclipse. I have no issue also to run "mvn:package" after I built the project in Eclipse. However, after I invoke "mvn:clean", if I run "mvn:package", I will get compilation error as it can't find dependency jar files under src/main/webapp/WEB-INF/lib. What I need to do is to rebuild the Eclipse project then "mvn:package". Therefore, I can't invoke "mvn:package" outside Eclipse IDE.
How to resolve this?
Thanks.
You have to put the not "Maven enabled artifacts" to an appropriate Maven Repository (Nexus, Artifactory what ever) and than change your project to use the dependencies appropriately. Furthermore either you do Maven or not but nothing in between. Maven is a build tool and not only for dependency management. After those changes working with Eclipse will work fine (if you use M2Eclipse). If you correctly use Maven you can do both things via Eclipse or call mvn package on command line.
If you can not set up a recommended environment (maven repository) you can add the dependencies as System dependencies to your pom.xml.
<project>
...
<dependencies>
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.2.3</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/foobar.jar</systemPath>
</dependency>
</dependencies>
...
</project>

Adding dependencies in Maven Netbeans

I've created a Maven project and added the dependencies (jar files) that I need; however, netbeans says that it still cannot find it.
Specifically in my case, I added the jmf-2.1.1e.jar file into my dependencies folder. When I go back to my program it still gives me the compile error that it cannot find the javax.media package.
Did you let Netbeans manage the dependency?
In your "Projects" listing, find and context+click on the "Dependencies" folder in the list. From the context menu, choose "Add Dependency".
This approach works at least in NetBeans 7.4 and 8.0 beta.
Make sure that your pom.xml has the following snippet that defines the dependency
<dependencies>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jmf</artifactId>
<version>2.1.1e</version>
</dependency>
</dependencies>
The dependency is available in Maven Central. Add the pom snippet manually to the pom.xml and run Maven in the shell and let it download the dependency. This should resolve your issue.
Maven automatically downloads the dependency once specified in the pom.xml. For this you would have to build your project with the dependency as specified by Tim Sparg.