Java Maven + Eclipse + servlet-api.jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3223935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
maven + eclipse + servlet-api.jar
提问by jwaliszko
I'm using Eclipse along with plugin m2eclipse to build and manage my project. In POM, I have included entry for servlet-api:
我使用 Eclipse 和插件 m2eclipse 来构建和管理我的项目。在 POM 中,我包含了 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 installis correct, file is notincluded into WEB-INF\lib, deployment to tomcat is working, program is working, it's ok.
提供范围,不包括.jar 文件到.war 包,(tomcat servlet 容器已经提供)。通过mvn install编译是正确的,文件没有包含在WEB-INF\lib 中,部署到 tomcat 工作正常,程序工作正常,没关系。
But, the case starts inside Eclipse. After starting my web application from eclipse, i'm getting error:
但是,这个案例是从 Eclipse 内部开始的。从 Eclipse 启动我的 Web 应用程序后,出现错误:
\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
\WEB-INF\lib\servlet-api-2.5.jar) - jar 未加载。请参阅 Servlet 规范 2.3,第 9.7.2 节。违规类: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 beputted 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.0including servlet-api.jar.
我不知道为什么,因为,Maven依赖关系(包括javac的-的servlet-2.5.jar)被列入作为Java EE的模块依赖,并应被推杆WEB-INF \ lib文件夹内,而从日食开始。另一方面,在 Eclipse 中,我提供了我的 apache tomcat 目录的路径,并且在项目内部,有对来自Apache Tomcat v6.0 的库的自动引用,包括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.
所以基本上,在从 POM 中删除对 servlet-api-2.5.jar 的引用后,该库从Maven Dependencies 中消失,并且我从 Eclipse 启动我的 Web 应用程序时没有例外。一切都很好......在 eclipse 中。
Of course without entry inside POM, this time mvn install faileswith the same exception, I have provided earlier.
当然没有进入 POM,这次mvn install 失败了,同样的异常,我之前已经提供了。
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 ?
有什么方法可以让它在不删除而不是插入引用的情况下工作,这取决于我想要做什么:用 maven 编译还是用 Eclipse 运行?
Regards
问候
采纳答案by matt b
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
\WEB-INF\lib\servlet-api-2.5.jar) - jar 未加载。请参阅 Servlet 规范 2.3,第 9.7.2 节。违规类: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.
只是来自应用服务器的警告,它会忽略您包含的 JAR 之一并且不会加载它。可以安全地忽略它。
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.
听起来问题在于 Eclipse 的部分/插件将您的项目加载到嵌入式应用程序服务器中 - 听起来它只是使用依赖项列表作为要捆绑的库路径,并且没有 Maven 范围的概念。
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).
就我个人而言,我会忽略这样的事情 - 你的 Maven 构建工作正常,除了这个可忽略的警告之外,在 Eclipse 中运行应用程序应该可以正常工作 - 否则你将不得不沿着一个工具期望的方式调整你的项目(网络Eclipse 的应用程序插件)与另一个(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).
(此外,我一直发现在 Eclipse 中将 webapps 作为“Web 项目”运行是一种痛苦,并且会导致各种奇怪的事情 - 不值得麻烦 - 如果您想在 servlet 中快速加载您的 Maven webapp 项目容器,只需使用mvn jetty:run
或mvn tomcat:run
。与 IDE 斗争可能是浪费时间)。
回答by Tim Wong
Install the plugin which named "Maven Integration for WTP", it can completely sovled this problem.
安装名为“ Maven Integration for WTP”的插件,完全可以解决这个问题。
Repository URL: http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/
存储库 URL:http: //download.jboss.org/jbosstools/updates/m2eclipse-wtp/