Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven webapp with maven-eclipse-plugin doesn't generate <dependent-module>

I use the eclipse:eclipse goal to generate an Eclipse Project environment. The deployment works fine. The goal creates the var classpath entries for all needed dependencies.

With m2eclipse there was the Maven Container which defines an export folder which was WEB-INF/lib for me. But i don't want to rely on m2eclipse so i don't use it anymore.

the class path entries which are generated by eclipse:eclipse goal don't have such a export folder.

While booting the servlet container with WTP it publishes all resources and classes except the libraries to the context.

Whats missing to publish the needed libs, or isn't that possible without m2eclipse integration?

Enviroment

  • Eclipse 3.5 Java EE Galileo
  • Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
  • Java version: 1.6.0_14
  • m2eclipse

The maven-eclipse-plugin configuration

    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-eclipse-plugin</artifactId>
     <version>2.8</version>
     <configuration>
      <projectNameTemplate>someproject-[artifactId]</projectNameTemplate>
      <useProjectReferences>false</useProjectReferences>
      <downloadSources>false</downloadSources>
      <downloadJavadocs>false</downloadJavadocs>

      <wtpmanifest>true</wtpmanifest>
      <wtpversion>2.0</wtpversion>
      <wtpapplicationxml>true</wtpapplicationxml>
      <wtpContextName>someproject-[artifactId]</wtpContextName>

      <additionalProjectFacets>
        <jst.web>2.3</jst.web>
      </additionalProjectFacets>
     </configuration>
    </plugin>

The generated files

After executing the eclipse:eclipse goal, the dependent-module is not listed in my generated .settings/org.eclipse.wst.common.component, so on server booting i miss the depdencies.

This is what i get:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
  <wb-module deploy-name="someproject-core">
    <wb-resource deploy-path="/" source-path="src/main/java"/>
    <wb-resource deploy-path="/" source-path="src/main/webapp"/>
    <wb-resource deploy-path="/" source-path="src/main/resources"/>
  </wb-module>
</project-modules>

Update for upcoming readers

The problem here was the deviant packaging-type, if u use maven-eclipse-plugin please validate the use of <packaging>war</packaging> or ear.

The following problems are marked of the situations that i have two build-lifecycles in one maven pom.

like image 593
Christopher Klewes Avatar asked Apr 26 '10 13:04

Christopher Klewes


1 Answers

Whats missing to publish the needed libs, or isn't that possible without m2eclipse integration?

I'm not sure to understand the problem. I've used the maven-eclipse-plugin with maven webapps during a long time with success. So, does the deployment on a Server work or not? Is the application usable or not? Can you clarify?

Just in case, I did a quick test on a newly created webapp with your plugin configuration which looks ok. I just removed the jst.java facet and configured the maven-compiler-plugin instead:

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <target>1.5</target>
    <source>1.5</source>
  </configuration>
</plugin>

And I added a dependency on log4j. Then, when I run mvn eclipse:eclipse, this is what I get in the generated .settings/org.eclipse.wst.common.component:

<project-modules id="moduleCoreId" project-version="2.0">
  <wb-module deploy-name="example-mvn-Q2713648">
    <property name="context-root" value="example-mvn-[artifactId]"/>
    <wb-resource deploy-path="/" source-path="src/main/webapp"/>
    <property name="java-output-path" value="/target/classes"/>
    <dependent-module archiveName="log4j-1.2.14.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/var/M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar">
      <dependency-type>uses</dependency-type>
    </dependent-module>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
  </wb-module>
</project-modules>

The log4j dependency is there and gets published. What did I miss?


Update: I pasted the provided pom in my war project, changed it to use the version 2.8 of the eclipse plugin and removed src/main/webapp from the resources element (it's not a resource) and this is what I get when running mvn eclipse:eclipse:

<project-modules id="moduleCoreId" project-version="2.0">
  <wb-module deploy-name="example-mvn-Q2713648">
    <property name="context-root" value="example-mvn-[artifactId]"/>
    <wb-resource deploy-path="/" source-path="src/main/webapp"/>
    <property name="java-output-path" value="/target/classes"/>
    <dependent-module archiveName="hsqldb-1.8.0.10.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/var/M2_REPO/hsqldb/hsqldb/1.8.0.10/hsqldb-1.8.0.10.jar">
      <dependency-type>uses</dependency-type>
    </dependent-module>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
  </wb-module>
</project-modules>

Looks fine to me.

Update 2: As I wrote in a comment to your own answer, I don't think the eclipse plugin will generate a dynamic web module for a project with a packaging of type jar. If you change the packaging war, it should behave as expected. I'm pretty sure this is the cause of your troubles.

like image 172
Pascal Thivent Avatar answered Oct 20 '22 18:10

Pascal Thivent