views:

2679

answers:

2

I've got m2eclipse plugin installed and there's no problem syncing compile time dependencies that appear in pom.xml.

Now, I add JPA + Hibernate(or whatever) dependency that maven catches up just fine when doing mvn jetty:run.

The problem is, Eclipse doesn't. So I don't get those extra .jars deployed on the referenced tomcat when I launch the web app from eclipse.

Is there a way to add this kind of web runtime dependencies to Eclipse? Don't really like the idea of manually editing org.eclipse.wst.common.component.

+9  A: 

I have found that any time you update a project's POM it helps to rerun m2eclipse or it will not see the new external dependencies.

If you have not tried to run this since you added your new dependencies ( JPA + Hibernate or whatever ) to your POM then give it a shot and see if it works.

mvn clean install eclipse:clean eclipse:eclipse eclipse:m2eclipse

Please note that after you execute this, you will probably need to refresh your Eclipse projects for the changes to take effect.

It might not require all of these arguments to work, but I sort of added them all at one point just to make certain. You can tweak the list of arguments to get it to the point that it works for you.

Doing this may blow away some of your Eclipse preferences for your project, so hopefully you have everything needed to rebuild your project already in your POM. For instance, I have a bunch of extra things in one of my POMs to ensure that things like springnature and springbuilder are added to my eclipse project when maven is used to rebuild the eclipse project.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-eclipse-plugin</artifactId>
      <configuration>
        <additionalProjectnatures>
          <projectnature>
            org.springframework.ide.eclipse.core.springnature
          </projectnature>
          <projectnature>
            org.eclipse.wst.common.project.facet.core.nature
          </projectnature>
          <projectnature>
            org.eclipse.wst.common.modulecore.ModuleCoreNature
          </projectnature>
          <projectnature>
            org.eclipse.jem.workbench.JavaEMFNature
          </projectnature>
        </additionalProjectnatures>
        <additionalBuildcommands>
          <buildcommand>
            org.eclipse.wst.common.project.facet.core.builder
          </buildcommand>
          <buildcommand>
            org.eclipse.wst.validation.validationbuilder
          </buildcommand>
          <buildcommand>
            org.springframework.ide.eclipse.core.springbuilder
          </buildcommand>
        </additionalBuildcommands>
        <wtpversion>1.5</wtpversion>
      </configuration>
    </plugin>
  </plugins>
</build>

This last bit was added as a warning! Would hate for someone to take a working Eclipse project and destroy a bunch of the configuration if they were not already prepared for the consequences of running the eclipse:* commands.

Beau Simensen
Thanks.What exactly do you mean saying 're run m2eclipse'?For now I've got away with running just `mvn eclipse:eclipse -Dwtpversion=2.0` but really want to get a deeper understanding of the subject.
alex
Thanks for the edit, it basically provided me with a direction: create an eclipse project, customize all of it's 'natures'. Create a blank mvn eclipse:eclipse proj. Diff into pom.xml so that mvn eclipse:eclipse would generate exactly the same bunch of eclipse config files. Ugly though.
alex
Yup! Exactly. It is very ugly. We tried a couple of Maven plugins and this was the "best", but it definitely is a PITA. In some installs (mine in particular) it may lose the J2EE Module Dependencies and takes quite a bit of work to get it to publish them properly. Hope you don't run into THAT.
Beau Simensen
A: 

I have found other solution. In my case there is WAR which depends on some JARs. Some JARs come from dependant projects (and they are deployed), and some are just plain dependencies (hibernate, spring, etc.).

I've spent few hours trying to determine why JARs from dependant projects are deployed and other - don't.

My solution was to create WEB-INF/lib folder in my WAR project! Usually you don't need them, because Maven2 creates this lib during package phase. In eclipse this is necessary.

My Eclipse is 3.6M4 and m2eclipse is 0.9.9.200912160759.

Grzegorz Grzybek