views:

1560

answers:

3

I working with a maven project in eclipse and am having trouble with getting the deployment to work without some manual editing of xml files.

When I build the project through maven I get a org.eclipse.wst.common.component xml file in my .settings folder. The file looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="ins-web">           
        <wb-resource deploy-path="/" source-path="/WebContent"/>
        <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/java"/>
        <property name="context-root" value="ins-web"/>
        <property name="java-output-path"/>
    </wb-module>
</project-modules>

The following line is causing the problem:

<wb-resource deploy-path="/" source-path="/WebContent"/>

Its looking to deploy everything below the WebContent folder when really it should be looking in src/webapp. The line should therefore look like this:

<wb-resource deploy-path="/" source-path="/src/webapp"/>

If I change it manually then it all works fine but I'd like to know if there is a way to avoid manually changing the file to make the build process easier for other people on my team.

A: 

How are you generating your eclipse files. Are you using the m2eclipse Eclipse plugin or are your using the maven-eclipse-plugin? m2eclipse is a plugin for Eclipse, run inside Eclipse. the maven-eclipse-plugin is a Maven plugin run from the cmd line to generate Eclipse project files based on your pom.xml.

I have always had better success using the maven-eclipse-plugin. The authors of m2eclipse do not suggest you try to use both plugins together.

If you are using the maven-eclipse-plugin, you should check a couple of things.

  1. Use the latest maven-eclipse-plugin version 2.7.
  2. Make sure your project is a 'war' packaging'
  3. Configure the maven-war-plugin as well and set the war source directory as you see fit. Add the following snippet to your pom.xml. This is how the maven-eclipse-plugin determines where your webapp lives.
  <plugin>  
    <artifactId>maven-war-plugin</artifactId>  
    <version>2.1-beta-1</version>  
    <configuration>  
      <warSourceDirectory>src/webapp</warSourceDirectory>  
    </configuration>  
  </plugin>

After making these changes and running mvn eclipse:clean eclipse:eclipse again, you should see the expected value in your component file.

Peter Lynch
Hi Peter,i am not using the maven-eclipse-plugin. I run all maven commands from the command line.I did a search across my project for a place to set "warSourceDirectory" but could not find one...
Gearóid
It sounds like you think the maven-eclipse-plugin is an Eclipse plugin run inside eclipse. It is not. It is a Maven plugin executed from the cmd line. warSourceDirectory is part of the maven-war-plugin configuration found inside your Maven pom.xml for your project.
Peter Lynch
A: 

Thank you Peter, The above post helped me with a problem when adding a new maven project to eclipse, and during runtime I had a Context initialization failed creating beans: the classes were not found in this new project.

I found out and edited manually the file org.eclipse.wst.common.component and added this new project, and with this post I now know it can be generated with

mvn eclipse:clean eclipse:eclipse

Luis Rosa
A: 

Unfortunately, "mvn eclipse:clean eclipse:eclipse" does not generate the same files that Eclipse when creating a new project (I mean inside ".settings"). And therefore, (for example) the item "Java EE Module Dependencies" does not appear within the project properties. Is there any way to edit the file "org.eclipse.wst.common.component" without using "mvn eclipse:clean" and without doing it manually? Regards

Lucas
Pascal Thivent