maven中的<scope>
来源:互联网 发布:政府网络维护员工资 编辑:程序博客网 时间:2024/06/05 02:51
我们在用maven和eclipse开发WEB应用的时候,需要把 servlet-api和jsp-api加入进来,要不然编译不会通过,加入进来之后在打包的时候maven自动把所有的依赖包都放到lib下面,如果你在tomcat下面运行就会有问题,因为tomcat发现你的web应用的lib中包含了servlet-api,他会报错。
- validateJarFile(D:\springsource\apache-tomcat-6.0.24\wtpwebapps\semwinner\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
validateJarFile(D:\springsource\apache-tomcat-6.0.24\wtpwebapps\semwinner\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
- org.apache.jasper.JasperException: java.lang.NullPointerException
- org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:527)
- org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:359)
- org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
- org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
- javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
- org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
- org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:163)
- org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
- org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
org.apache.jasper.JasperException: java.lang.NullPointerExceptionorg.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:527)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:359)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:163)org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
解决这个问题的方法就是使用<scope>标签,如下
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.4</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jsp-api</artifactId>
- <version>2.0</version>
- <scope>provided</scope>
- </dependency>
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency>
这里的意思是说,编译的时候用到servlet-api和jsp-api,但在打包的时候不用这两个依赖。
在maven的官方中是这样描述的
Dependency Scope
Dependency scope is used to limit the transitivity of a depedency, and also to affect the classpath used for various build tasks.
There are 6 scopes available:
- compile
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects. - provided
This is much like compile , but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive. - runtime
This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath. - test
This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. - system
This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository. - import (only available in Maven 2.0.9 or later)
This scope is only used on a dependency of type pom in the <dependencyManagement> section. It indicates that the specified POM should be replaced with the dependencies in that POM's<dependencyManagement> section. Since they are replaced, dependencies with a scope ofimport do not actually participate in limiting the transitivity of a dependency.
如果你这样做了,但使用eclipse+tomcat做测试的时候发现servlet-api还是被打包到lib下面了,你要把maven插件中的WTP也安装一下,问题应该就解决了。
- maven中的<scope>
- maven 中的scope简介
- Maven中的Scope-System
- Maven 依赖中的scope
- Maven依赖中的scope
- maven中的scope属性
- Maven依赖中的scope详解
- Maven依赖中的scope详解
- maven依赖中的scope使用
- Maven依赖中的scope详解
- Maven依赖中的scope详解
- 关于maven中的scope用法
- Maven依赖中的scope详解
- 浅谈maven中的scope,systempath
- Maven 中的scope的值
- Maven依赖中的scope详解
- maven中pom.xml中的scope讲解
- maven scope
- ios 导航栏风格
- Java传统Socket实例——TimeServer
- android图像处理之灰度化
- sql语句小练习
- jsp 解析xml
- maven中的<scope>
- Linux主分区,扩展分区,逻辑分区的联系和区别
- Hdu 3999 - The order of a Tree
- WebKit 内核源代码分析系列
- mysql命令大全
- unity基础开发----导入模型碰撞检测
- Xml 反序列化
- Aptana常用设置
- 贪心算法之最小生成树Kruskal