最近用intellij idea新建了一套maven web项目,用tomcat7-maven-plugin运行(直接运行程序,不是war包)。
项目集成了Spring MVC框架,对jsp页面的处理依赖下面两个jar包:
<dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2.1-b03</version></dependency><dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>3.0-alpha-1</version></dependency>
但启动时报错:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run (default-cli) on project configuration: Could not start Tomcat: Failed to start component [StandardServer[-1]]: Failed to start component [StandardService[Tomcat]]: Failed to start component [StandardEngine[Tomcat]]: A child container failed during start -> [Help 1]
可能是这两个包跟tomcat插件中的包冲突导致的。对上面两个依赖包添加限定后,项目可以正常启动。
<scope>provided</scope>
但是当控制层返回视图时,又出现新的错误:
java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config
应该是缺少jstl的jar包,继续添加依赖:
<dependency> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl-api</artifactId> <version>1.2-rev-1</version></dependency>
启动时又出现之前的错误:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run (default-cli) on project configuration: Could not start Tomcat: Failed to start component [StandardServer[-1]]: Failed to start component [StandardService[Tomcat]]: Failed to start component [StandardEngine[Tomcat]]: A child container failed during start -> [Help 1]
试着运行一下war包,没有问题,难道又是scope的问题,加上provided无效,改成runtime也无效。难道是servlet版本(我用的是2.5)的问题吗?
切换servlet版本后依然报同样的错。
莫非是jstl版本的问题,是不是版本高了?
试着把1.2后面的内容去掉,一切OK!
附上最后的依赖配置:
<dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2.1-b03</version> <scope>provided</scope></dependency><dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>3.0-alpha-1</version> <scope>provided</scope></dependency><dependency> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl-api</artifactId> <version>1.2</version></dependency>