开发者

maven, eclispse and wtp broke for no reason: it stopped putting the mvn depentent jars in the WEB-INF/lib

Ive been running eclipse (Helios Build id: 20100617-1415), sonotype maven for eclipse version 2 (0.1.0.20100xxx) for many months without issue.

I can do "mvn install" on the command line, and get a perfect war, and I could run the webapp in eclipse local tomcat no problem.

Then this morning, I started tomcat in eclipse, hit the serlvet, and got lots of class not found. Looking where eclipse puts libs in the webapp .metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\ge-api\WEB-INF\lib, I see none of the standard dependent libs (e.g. log4j).

I did my usual mvn mantra:

  1. close elcipse
  2. go to root of parent project
  3. mvn clean
  4. mvn install
  5. mvn elcipse:eclipse
  6. restart eclipse
  7. refresh all the projects, starting with the parent.

This did not help.

I tried every m2eclipse option available - nothing helped.

So I tried the tomcat mantra:

  1. open eclipse
  2. go to server tab
  3. remove webapp
  4. window->preferences->server->runtime environments
  5. remove tomcat 6
  6. restart eclipse
  7. add tomcat 6 again.
  8. add the webapp to it again.
  9. restart the tomcat server in eclipse

This resulted in the same problem, maven and elcipse hate each other and refuse to speak. And I changed not one thing, not even a line of comments, between it working and it not working.

I checked every config - the required jars are correctly in as dependences in every right place. See below - all the jars are in the class path - correctly put there by maven.

maven, eclispse and wtp broke for no reason: it stopped putting the mvn depentent jars in the WEB-INF/lib

there is also an "order and export" tab, although I have no idea what the export part means:

maven, eclispse and wtp broke for no reason: it stopped putting the mvn depentent jars in the WEB-INF/lib

The above dialogue has check boxes next to the libs, so I tried clicking on them (hey - I am desperate). When I do this and hit ok, I always get this error:

maven, eclispse and wtp broke for no reason: it stopped putting the mvn depentent jars in the WEB-INF/lib

I removed tomcat from my PC, re-added and get same error. I can happily run a test Webapp project which has no libraries, so it seems to be fine.

After 10 hours of hair tearing, I notcied something in the warnings:

Description Resource Path Location Type Classpath entry M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar will not be exported or published. Runtime ClassNotFoundExceptions may result. ge-api P/ge-api Classpath Dependency Validator Message

What on earth caused this?

There are lots of posts on this error, which seem to say you have to

"open the J2EE Module Dependencies" UI and select the classpath entry in the table of potential entries (the resolved JARs will be packaged in either WEB-INF/lib or the root of the EAR, referenced via the Manifest classpath, depending on the type of dependency"

However, I dont have anything like "J2EE module dependencies" anywhere in eclipse.

Here are my facets/properies:

maven, eclispse and wtp broke for no reason: it stopped putting the mvn depentent jars in the WEB-INF/lib

See, no J2EE, and no configuration options.

So in desperation, I try the warnings "quick fix".

"Mark the associated raw classpath entry as publish/export dependency."

It worked before, so why do I have to do this now? Anway, I try this on one of the 10 libs for one of the 4 sub projects which have identical dependencies manged till now by the parent pom (yes, ill have to do this hack 40 times), and now I see 2) things have happened:

  1. Its added "publish/export dependecy in the libraries tab of the Java Build path:

maven, eclispse and wtp broke for no reason: it stopped putting the mvn depentent jars in the WEB-INF/lib

I cant find any way of manually doing this if I didnt use the auto fix system.

  1. It gives me more warnings:

"Description Resource Path Location Type Classpath entry M2_REPO/log4j/log4j/1.2.15/log4j-1.2.15.jar is marked for publish/export but is not exported on the project classpath. Classpath visibility within Eclipse and at runtime will differ. ge-core P/ge-core Classpath Dependency Validator Message"

Whats the point of using maven to manage classpaths?

So now Im hacking away till something works, with no hope of going back to yesterday when everthing worked without issues: I created the project with maven, used pom files to do everything, and eclipse went along. Until now.

Here is my parent pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.skillkash.ge</groupId>
<artifactId>ge-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>ge-parent</name>
<modules>
 <module>ge-api</module>
 <module>ge-core</module>
 <module>ibo-core</module>
</modules>
<build>
<plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
    <source>1.6</source>
    <target>1.6</target>
   </configuration>
  </plugin>
 </plugins>
</build>
<dependencies>
<dependency>
 <groupId>log4j</groupId>
 <artifactId>log4j</artifactId>
 <version>1.2.15</version>
 <exclusions>
  <exclusion>
   <groupId>javax.jms</gr开发者_JAVA技巧oupId>
   <artifactId>jms</artifactId>
  </exclusion>
  <exclusion>
   <groupId>com.sun.jdmk</groupId>
   <artifactId>jmxtools</artifactId>
  </exclusion>
  <exclusion>
   <groupId>com.sun.jmx</groupId>
   <artifactId>jmxri</artifactId>
   </exclusion>
  </exclusions>
 </dependency>
 <dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>5.12.1</version>
 </dependency>
</dependencies>
</project>

Here is my local webapp pom:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>ge-parent</artifactId>
    <groupId>com.skillkash.ge</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.skillkash.ge</groupId>
<artifactId>ge-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ge-api Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.4</version>
    <scope>provided</scope>
  </dependency>    
  <dependency>
   <groupId>com.skillkash.ge</groupId>
   <artifactId>ibo-core</artifactId>
    <version>0.0.1-SNAPSHOT</version>
   <scope>compile</scope>
  </dependency>
  <dependency>
   <groupId>com.skillkash.ge</groupId>
   <artifactId>ge-core</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   </dependency>
   </dependencies>
 <build>
    <finalName>ge-api</finalName>
</build>
</project>

And heres my project layout in eclipse:

maven, eclispse and wtp broke for no reason: it stopped putting the mvn depentent jars in the WEB-INF/lib

Does any one know what went wrong, and what is the correct way to fix it?


My suggestions:

  • do NOT use eclipse:eclipse when using m2eclipse (this is not supported)
  • delete the project from your workspace and delete the .eclipse, .classpath, .settings from the file system
  • reimport the project into your workspace via Import... > Existing Maven Projects
  • do not mess with anything manually

Oh, and as a side note, I would personally configure the WTP to take full control of Tomcat instead of using workspace metadata (but this shouldn't be the root cause of the troubles).


Two ideas:

1) The Eclipse Mantra: Start Eclipse. Select File->Close All. Close and restart Eclipse.

2) Assuming you use a source version control system: Delete Eclipse. Delete Tomcat. Delete workspace. Reinstall Eclipse (you may want to keep a zipped Eclipse with all packages you need pre-installed at hand for this purpose if you keep having such problems (as I do)). Re-install Tomcat: I recommend just unzipping Tomcat somewhere and start/stop it from Eclipse rather than a Tomcat system install. Check-out your project from your source repository; hopefully the latest version works, if not try an older one.


Whenever I find some issues with the libraries this is what I do and it works: ( note: I'm not using the maven eclipse plugin which almost never works for me )

  1. mvn dependency:resolve
  2. mvn eclipse:eclipse
  3. Refresh eclipse project.

    • regards, Shoubhik


For me this typically works, if a Maven project is broken in Eclipse:

  1. "Right Click" on project
  2. -> "Maven"
  3. -> "Update project..."
  4. -> "Ok"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜