我们在用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
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)
解决这个问题的方法就是使用<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>
这里的意思是说,编译的时候用到servlet-api和jsp-api,但在打包的时候不用这两个依赖。
在maven的官方中是这样描述的
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 of import
do not actually participate in limiting the transitivity of a dependency.
如果你这样做了,但使用eclipse+tomcat做测试的时候发现servlet-api还是被打包到lib下面了,你要把maven插件中的WTP也安装一下,问题应该就解决了。
分享到:
相关推荐
<scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework....
<scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <scope>provided</scope> </dependency> <dependency...
<scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> <scope>provided</scope> </dependency> </...
主要介绍了maven依赖关系中的<scope>provided</scope>使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
1、先在pom.xml文件中加入<build></build>标签 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.1</version> ...
logback-kafka-appender 该追加程序使您的应用程序可以将其应用程序日志直接发布到Apache Kafka。 登录不兼容警告 由于Logback Encoder API中的重大更改,您至少需要使用... < scope>runtime</ scope> </ dependenc
): <dependency><groupId>com.github.neothemachine</groupId><artifactId>gwt-webdriver-junit-runstyle</artifactId><version>0.0.1-SNAPSHOT</version><scope>test</scope></dependency>调整gwt-maven-plugin...
<scope>test</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <!-- mybatis依赖的jar包 --...
<scope>system</scope> <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope...
<scope>system</scope> <systemPath>${basedir}/src/main/resources/jar/kingbase8-8.6.0.jar</systemPath> </dependency> jdbc driver-class-name: com.kingbase8.Driver url: jdbc:kingbase8://127.0.0.1:54321/...
<scope>provided</scope> </dependency> <!-- 文件上传组件 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload....
<scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!--...
<scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> <scope>provided</scope> </...
<scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies...
<scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <scope>provided</scope> </dependency> </dependencies> <!-- 如果不添加此...
Maven在编译项目主代码的时候需要使用一套classspath。总共有三种classpath,分别对应于Maven编译项目主代码的时候、Maven编译和执行测试的时候、实际运行Maven项目的时候。
ojdbc6(此包解决mybatis_plus查询时分秒为0问题),springboot项目+oracle11g就用这个jdbc就行,... <scope>system</scope> <systemPath>${pom.basedir}/src/main/resources/lib/ojdbc6.jar</systemPath> </dependency>
<scope>import</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> ...
<scope>test</scope> </dependency> 手动安装至本地maven仓库 mvn install:install-file -DgroupId=org.springside -DartifactId=springside-core -Dversion=4.2.2.GA -Dfile=./springside-core-4.2.2.GA.jar -...
注释掉原有的aspose依赖,将下载文件挡在lib文件夹下,并在pom文件中添加新的依赖。... <scope>system</scope> <systemPath>${project.basedir}/lib/aspose-cad-23.7.jar</systemPath> </dependency>