views:

30

answers:

2

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.

look, all the jars are put in the class path by maven

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

alt text

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:

alt text

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:

alt text

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:

alt text

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</groupId>
   <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"&gt;
<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&lt;/url&gt;
<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:

alt text

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

+1  A: 

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.

Carsten
Thanks for the answer. I should have said but I tried suggestion 1) (restart eclipse) several times - it occasionally works when elcipse gets confused.
wingnut
2) is a absolute last resort, as it takes days to install all the plugins and configure everything for all the projects. I do have tomcat separately installed, and always assumed it was using this one. Are you saying its using an eclipse internal tomcat?
wingnut
about tomcat: Sorry, didn't mean to confuse. Tomcat (for Windows) comes in 2 flavours: as a .zip file and as a Windows Service Installer. My remark was just recommending the first version over the second as I found it easier to work with from Eclipse (and uninstall is as simple as deleting the unzipped folder)
Carsten
+1  A: 

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).

Pascal Thivent
Great answer - thanks! I created this project using m2eclipse plugin webapp protytype. However, either this is buggy or only does half the job, as it didnt setup any of the source paths (e.g. src/main/java). About once a month, the whole environment stops working for no apparent reason, e.g. sudenly cant reslove any of the sibling project references. Generally I spend several hours trying to find what the problem is (as nothing has changed), then resort to the maven mantra which, until now, is the only thing which worked. However, I will try the above.
wingnut
@wingnut The webapp archetype deliberately doesn't assume you'll put sources in the webapp and doesn't create directories like `src/main/java`, `src/main/resources`, `src/test/java`, etc. It's up to you to create them.
Pascal Thivent