views:

375

answers:

2

Hello,

I'm using Eclipse along with plugin m2eclipse to build and manage my project. In POM, I have included entry for servlet-api:

  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
  </dependency>

Scope is provided, not to include the .jar file to .war package, (it is already provided by the tomcat servlet container). Compilation by mvn install is correct, file is not included into WEB-INF\lib, deployment to tomcat is working, program is working, it's ok.

But, the case starts inside Eclipse. After starting my web application from eclipse, i'm getting error:

\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

I don't know why, because, Maven Dependencies(including javac-servlet-2.5.jar) are included as Java EE Module Dependencies, and should be putted inside WEB-INF\lib folder, while starting from eclipse. On the other hand, in eclipse I've provided path to my apache tomcat directory, and inside project, there are automatic references to libraries from Apache Tomcat v6.0 including servlet-api.jar.

So basically, after removeing reference from the POM to servlet-api-2.5.jar, that library dissapears from Maven Dependencies, and I get no exception while starting my web app from eclipse. Everything is fine... in eclipse.

Of course without entry inside POM, this time mvn install failes with the same exception, I have provided earlier.

Is there any way to make it working without removing and than inserting reference, depending of what I want to do: compile with maven or run with Eclipse ?

Regards

A: 

This

\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

is simply a warning from the app server that it is ignoring one of your included JARs and will not load it. It can be safely ignored.

Sounds like the issue is with the portion/plugin for Eclipse that loads your project in an embedded app server - sounds like it simply uses the list of dependencies as what to bundle as the library path, and has no concept of Maven scopes.

Personally I would ignore something like this - your Maven build is working fine, running the app within Eclipse should work fine besides this ignorable warning - otherwise you'll have to go down the path of tweaking your project for what one tool expects (the web app plugin for Eclipse) versus another (Maven).

(Also I've always found that running webapps as "Web projects" within Eclipse is a pain in the butt, and leads to all sorts of oddities - not worth the hassle - if you want to quickly load your Maven webapp project in a servlet container, simply use mvn jetty:run or mvn tomcat:run. Fighting with IDEs can be a waste of time).

matt b
A: 

I have no idea why you're facing this problem. I'm using Maven and have numerous web applications in my eclipse workspace and have no problem deploying them with the WTP (the WTP integration support from m2eclipse just works), I don't get the warning you're showing.

Pascal Thivent
Running webapp has faild in eclipse only at the first time (while servlet mvn dependency was added). So, I've removed the maven dependency, next rebuilt and run. It was ok, as I suspected. Next time, I have added the maven dependency (after all, it is required by maven), and tried to build and run the project in eclipse once more, just for couriosity. And it was working this time. Eclipse has to cached something or, I don't know, but it is working so it's ok, and there is no reason to think about that anymore;].
Jarek Waliszko