9

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.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Christopher Klewes
  • 11,181
  • 18
  • 74
  • 102
  • 1
    Are you sure the `maven-eclipse-plugin` is correctly configured in the project where you run `eclipse:eclipse`? Why do you get a `project-version="1.5.0"`? This is weird, this doesn't reflect the configuration. – Pascal Thivent Apr 27 '10 at 07:02
  • Its exactly what i pasted, very strange. I can delete the `eclipse` files and run `eclipse:eclipse` again, it produces the same output. – Christopher Klewes Apr 27 '10 at 07:10
  • 1
    I can't reproduce the problem. Can you post your whole pom? (maybe on http://pastie.org if it's too big). – Pascal Thivent Apr 27 '10 at 07:31
  • I started an small example project, with maven `mvn archetype ... webapp` and inserted my `maven-eclipse-plugin` block, this turns out to work as expected and generates an ``. It seems that a configuration i made interfere this behaviour. I would provide the whole pom in a few minutes (just make it anonymous). – Christopher Klewes Apr 27 '10 at 08:09

2 Answers2

4

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.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • Thank you for your answer, this helps me for what i have to expect. But i adjusted my question, unfortunately i don't get this `` stuff, maybe something else doing wrong? – Christopher Klewes Apr 27 '10 at 05:55
  • I added the example pom of my project in an additional answer, just to notify you. – Christopher Klewes Apr 27 '10 at 08:18
  • Yes, we discovered the problem. As i changed `jar` to `war` it generates the ``. For me it isn't consistently implemented, why does the `maven-eclipse-plugin` cares of the packaging definition? ... Awwww thats so bad, because i need the capabilities of the `webapp` and the `war-packaging` but my artifact has to be a `jar`. Unfortunately i am out of ideas ... do you have one more? :) – Christopher Klewes Apr 27 '10 at 09:25
  • 1
    @chrsk The maven-eclipse-plugin is totally consistent with the way Maven works: a WAR is expected to be packaged as a `war` or you simply don't get the right lifecycle bindings for a war. In other words, a war is a war, a jar is a jar. Your case is somehow *very* particular (a jar that expands itself into a war) and not assumed by Maven. Can't you use a war and use the [`archiveClasses`](http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#archiveClasses) optional parameter to create your framework jar? – Pascal Thivent Apr 27 '10 at 09:59
  • We have a very model-based approach, where the model will be generated into views and processes etc., thats a fact we can't change. But why does `maven-eclipse-plugin` then generates anything? but thats another question. If you have a hint for me, let me know. Thank you very much for your work and posts until now, you helped me to clarify the situation. – Christopher Klewes Apr 27 '10 at 10:03
  • `archiveClasses` sadly doesn't works for me, because i have two different lifecycles, correclty as you pointed out a war is a war and a jar is jar. This leads to the situations that i need at "development-time" a full wtp compatible project, which i can start and develop easy, and at "product-time" an artifact which is packaged as jar. If i use `archiveClasses` i would have an war artifact with encapsulated classes, which leads me to nothing – Christopher Klewes Apr 27 '10 at 10:12
  • 1
    @chrsk I see. Then I'm afraid you'll have to patch the maven eclipse plugin or to set the packaging to war, generate the eclipse files, revert to jar. – Pascal Thivent Apr 27 '10 at 10:52
  • @Pascal Ok, just to let you know: We have compromised and support two ways to work with our project: a) set packaging to `jar`, deploy to mvn-repo, revert. b) using the `maven-dependency-plugin` and copy the libs to `WEB-INF/lib` so they can be copied by wtp and don't need to be configured as `dependent-modules` (disadvantage: no convinient sources, javadoc integration | advantage: no future maven -> wtp version problems (generation of `.component`) this can be configured as profile. Thank you again for your help, i gave you some upvotes! – Christopher Klewes Apr 27 '10 at 11:42
  • Would you be kind enough to remove the name of the project in `deploy-name` and `context-root` i published it accidently, i don't want to delete this question, for upcoming readers. Thank you in advance. – Christopher Klewes May 05 '10 at 13:54
0

The example pom (on pastie.org)

I've removed ~60 dependencies from the original pom.xml beside this nothing changed. You just have to create the webapp-archetype and paste the pom into the generated (by the archetype command)

mvn archetype:create 
     -DgroupId=example 
     -DartifactId=mvn 
     -DarchetypeArtifactId=maven-archetype-webapp

After this eclipse:eclipse leads to the generated .settings/org.eclipse.wst.common.component which now shows project-version="2.0" (after i did various changes from 1.0 to 1.5 and 2.0) but still the <dependent-module> is missing.

<project-modules id="moduleCoreId" project-version="2.0">
  <wb-module deploy-name="example-mvn-mvn">
    <wb-resource deploy-path="/" source-path="src/main/webapp"/>
    <wb-resource deploy-path="/" source-path="src/main/resources"/>
  </wb-module>
</project-modules>

Update (@Pascal Thivent): This is a good point. Our project (a web-framework) has in fact two mixed features. There is the jar-packaging which is used to provide the framework capabilities, while running it expands itself into the webapp-structure (WEB-INF/...)

But it should also be possible to run the framework with its extensions on a servlet container itself, so we can develop the base functionality without package it as jar and use it with a custom project. So the jar is correct here.


Update 2

The source code (EclipseWtpComponentWriter) of the maven-eclipse-plugin shows that this is hardcoded and there is no way to run into the then clause except setting the packaging to war, or did i miss something? :(

private void writeModuleTypeComponent( XMLWriter writer, String packaging,
                 File buildOutputDirectory, EclipseSourceDir[] sourceDirs, 
                 ArtifactRepository localRepository)
{
   if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ))
   { 
       // Adding the <dependent-modules> stuff
   }
}
Christopher Klewes
  • 11,181
  • 18
  • 74
  • 102
  • Oh you removed your comment, anyway i added an explanation for the `packaging jar`. – Christopher Klewes Apr 27 '10 at 08:49
  • 2
    Yes, I removed it because I thought you were expecting me to paste the content of your pom into a war project. But now that reread your question, I think that we found the problem: I don't think the eclipse plugin will generate a dynamic webmodule for a project with a packaging of type `jar`. If you change it to `war`, it should behave as expected. – Pascal Thivent Apr 27 '10 at 09:13