1

I'm developing a Java server application with Eclipse Indigo, which is deployed to Jetty. Now I'm trying to add authentication to the application with Spring Security. I've added the following definition to my business-layer-context.xml:

<security:http>
        <security:intercept-url pattern="/**" access="ROLE_USER" />
        <security:http-basic />
</security:http>

Now, the problem is that Eclipse gives me this error: Error occured processing '/MyServer/WEB-INF/business-layer-context.xml', which is caused by java.lang.NoClassDefFoundError: javax/servlet/Filter. When I deploy the application to Jetty, it works just fine, since Jetty contains the servlet API.
What would be the best way to make Eclipse understand that the application is deployed to servlet container and the API is therefore available? I could add the Jetty servlet JAR to project build path in Eclipse, but that would require each developer to configure the path to Jetty in Eclipse, and I'd like to keep developer specific configurations to the minimum.
So, is there a better way to get rid of the error?

Carlos
  • 2,503
  • 26
  • 29

2 Answers2

4

You need to include servlet-api.jar or relevant JAR that implements the Java Servlet API into your project build path.

In Eclipse, you will need to:

  • Right click your project, then "Properties".
  • "Java Build Path" -- > "Libraries"
  • Click on the "Add External JARS" button and find servlet-api.jar or any relevant jar that implements the Java Servlet API.

Once you're done, click OK and rebuild your project. The jar can be found in the Jetty lib folder since it runs your servlet application.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
0

Add the server library to your project lib and add it to the classpatH.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Nrj
  • 6,723
  • 7
  • 46
  • 58
  • Another approach I thought of, but it does not sound appealing either since I would need to add another otherwise unnecessary library to my project just to satisfy Eclipse. – Carlos Jun 30 '11 at 12:40