使用servlet API与Eclipse [英] Using servlet API with Eclipse

查看:188
本文介绍了使用servlet API与Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用部署到Jetty的Eclipse Indigo开发Java服务器应用程序。现在我试图使用Spring Security向应用程序添加身份验证。我将以下定义添加到我的 business-layer-context.xml 中:

 <安全:HTTP> 
< security:intercept-url pattern =/ **access =ROLE_USER/>
< security:http-basic />
< / security:http>

现在,问题是Eclipse给我这个错误:错误发生处理'/ MyServer /WEB-INF/business-layer-context.xml',这是由 java.lang.NoClassDefFoundError:javax / servlet / Filter 引起的。当我将应用程序部署到Jetty时,它的工作原理很好,因为Jetty包含servlet API。

使Eclipse了解应用程序部署到servlet容器的最佳方式是什么?可用?我可以添加Jetty servlet JAR来在Eclipse中创建项目的路径,但这需要每个开发人员在Eclipse中配置Jetty的路径,我希望将开发人员的具体配置保持在最低限度。

那么有没有更好的方法来摆脱错误?

解决方案

你需要包含 servlet -api.jar 或实现Java Servlet API的相关JAR到您的项目构建路径。



在Eclipse中,您将需要: / p>


  • 右键单击您的项目,然后右键单击属性。

  • Java Build Path 库

  • 点击添加外部JARS按钮,找到 servlet-api.jar 或任何实现Java Servlet API。



完成后,单击确定并重建项目。该jar可以在Jetty lib文件夹中找到,因为它运行您的servlet应用程序。


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?

解决方案

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.

这篇关于使用servlet API与Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆