java.lang.ClassNotFoundException:org.apache.jsp.index\u jsp
我有一个老的struts 1应用程序,它总是使用Ant构建的,我正在将其转换为使用Maven。我的应用程序的结构是模块化的,包含模块中有依赖关系管理。包含模块的dep mgmt部分包含:java.lang.ClassNotFoundException:org.apache.jsp.index\u jsp,jsp,maven,Jsp,Maven,我有一个老的struts 1应用程序,它总是使用Ant构建的,我正在将其转换为使用Maven。我的应用程序的结构是模块化的,包含模块中有依赖关系管理。包含模块的dep mgmt部分包含: <dependencyManagement> <dependencies> <dependency> <groupId>javax.servlet</groupId> <ar
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
...
</dependencies>
</dependencyManagement>
我从搜索中找到的所有信息都表明原因是javax.servlet jars中的版本冲突,但我的WEB-INF/lib目录中根本没有任何内容。我尝试过使用提供的范围、编译、甚至安装/pom
,但这些都没有任何帮助
tomcat日志中没有其他内容
我确认JSP正在编译中。我正在使用JSPCMaven插件
在我的子模块pom.xml中(不是包含的模块),我有:
<build>
<!-- default goal to run if somebody doesn't pick one (rarely matters) -->
<defaultGoal>install</defaultGoal>
<!-- resources and filtering - also see configuration under maven-war-plugin below -->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/resources/${env}.properties</filter>
<filter>src/main/resources/${env}.tokens</filter>
</filters>
<plugins>
<!-- begin - precompiling jsps -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<executions>
<execution>
<id>jspc</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<warSourceDirectory>${basedir}/src/main/webroot</warSourceDirectory>
<inputWebXml>${basedir}/src/main/webroot/WEB-INF/web.xml</inputWebXml>
<!--<workingDirectory>${basedir}/src/main/webroot</workingDirectory>-->
</configuration>
</execution>
</executions>
</plugin>
<!-- end - precompiling jsps -->
<!-- used to build warfiles -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<webResources>
<resource>
<directory>${pom.basedir}/src/main/webroot</directory>
<filtering>true</filtering>
<!--<targetPath>WEB-INF</targetPath>-->
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
安装
src/main/resources
真的
src/main/resources/${env}.properties
src/main/resources/${env}.tokens
org.codehaus.mojo
JSPCMaven插件
jspc
编译
${basedir}/src/main/webroot
${basedir}/src/main/webroot/WEB-INF/WEB.xml
org.apache.maven.plugins
maven战争插件
2
${pom.basedir}/src/main/webroot
真的
我可以在maven构建输出中看到正在编译JSP。但是我仍然得到JasperException。您使用的是什么版本的tomcat?在我看来,tomcat版本不支持您正在使用的servlet和jsp版本。您可以更改为下面这样的内容,或者查看您的tomcat版本所支持的内容,并相应地更改版本
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
javax.servlet
javax.servlet-api
3.0.1
假如
javax.servlet
jsp api
2
假如
我发布这篇文章已经有一段时间了,但我想我应该展示一下我是如何理解它的(正如我现在所记得的那样)
我做了一个Maven依赖关系树来查找依赖关系冲突,并删除了依赖关系中排除的所有冲突,例如:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
<version>1.1</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
嗯。我在我的项目中也遇到了同样的问题。我使用了IntelliJ Idea 14和Maven 8。
我注意到,当我向IDE添加一个tomcat目的地时,它自动链接了来自tomcat lib目录的两个JAR,它们是servlet api和jsp api。我在pom.xml中也有它们。我花了一整天的时间试图弄清楚为什么我会得到java.lang.ClassNotFoundException:org.apache.jsp.index\u jsp。这是正确的。这是因为存在依赖冲突。当我在pom.xml中向这两个jar添加provided时,我发现了一个快乐:)在其他答案的基础上添加了一个不适合我的答案:在我的情况下,错误是由于权限错误而发生的。该项目是在tomcat以root用户身份运行时部署的,后来以tomcat用户身份启动时,我从问题标题中得到了错误
我的解决方案是在unix系统上设置正确的权限,例如:
cd <tomcat-dir>
chown -R <tomcat-user> *
cd
chown-R*
在我的案例中,这是由于类似的原因造成的:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<include-prelude>/headerfooter/header.jsp</include-prelude>
<include-coda>/headerfooter/footer.jsp</include-coda>
</jsp-property-group>
</jsp-config>
*.jsp
/headerfooter/header.jsp
/headerfooter/footer.jsp
问题实际上是我的项目中没有header.jsp。然而,错误消息仍然说找不到index_jsp。我也花了半天时间试图修复这个问题
根目录似乎是我的项目pom.xml文件,具有依赖关系:
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
在我的例子中,通过为tomcat主路径设置正确的权限,问题得到了解决:
cd /opt/apache-tomee-webprofile-7.1.0/
chown -R tomcat:tomcat *
我在我的案例中手动将.war文件移动到/var/lib/tomcat9/webapps
解压后,在那个目录中做了“chown-R tomcat:tomcat*”,它解决了这个问题。我不得不删除tomcat的工作目录,因为它缓存了以前生成的文件。为此:
阻止雄猫
删除“工作”目录
启动雄猫
这将导致新生成工作目录。我使用的是6.0.35,它似乎支持Servlet 2.5和JSP 2.1。我意识到这是一个比我包含的更新版本的jsp api,所以我将我的升级到了2.2,这是最新的版本。我还做了一个mvn依赖关系树,确保依赖关系中没有冲突的版本。还是没有骰子。即使按照您的建议使用提供的
也无法修复它。您是否正在执行干净的构建/运行?你使用的是什么版本的maven?另外,您正在使用的jsp maven插件根本不需要。我相信您正在使用maven 2。我正在进行干净的构建;我定期清理IntelliJ的缓存。我使用的是ApacheMaven 3.1.1——是的,我将jsp预编译移到了prod概要文件中,后来才意识到我不需要(或不想要)开发人员使用它。坦白地说,在我意识到我知道得更好之前,这是一个很难理解的问题(“也许我需要预编译”)。我还是被卡住了,所以如果你想知道什么,我很想听。谢谢。
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
a) installing different (older/newer) tomcat like (Exactly what I did, because team is on older version)
b) changing dependency scope to 'compile'
c) update whole project dependencies to the actual version of Tomcat/lib provided APIs
d) put matching version of the jsp-api.jar in {tomcat folder}/lib
cd /opt/apache-tomee-webprofile-7.1.0/
chown -R tomcat:tomcat *