今天在自己家里的电脑上改一个项目,安装的是社区版的 IntelliJ Idea, 没有办法安装 Tomcat 插件来启动项目。尝试用 jettry runer 启动,结果报
java.lang.IncompatibleClassChangeError: class org.eclipse.jetty.annotations.AnnotationParser$MyClassVisitor has interface
org.objectweb.asm.ClassVisitor as super class
在网上找了半天也没解决,于是改为用 maven-tomcat-plugin,配置很简单,如下:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
运行也简单,命令行执行:
mvn tomcat7:run
不过马上就报错了,提示:
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/catalina/loader/WebappClassLoader) previously initiated loading for a different type with name "javax/servlet/ServletContext"
提示很明显看出来是 servlet-api 版本不兼容。解决方法为,将 pom.xml 里的 servlet-api 改为 provided,否则项目启动时与 tomcat 内置 servlet 冲突。再次运行,又报错了:
Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application
[/demo-web] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies.
The class hierarchy being processed was [org.jaxen.util.AncestorOrSelfAxisIterator->org.jaxen.util.AncestorAxisIterator->
org.jaxen.util.AncestorOrSelfAxisIterator]
多运行了几次,发现有 3 次成功,2 次报上面的错,网上找到的解释 tomcat启动时检测到循环继承而栈溢出的问题,将项目传递依赖的 jaxen exclude 之后重新运行成功。
来源:oschina
链接:https://my.oschina.net/u/4366825/blog/3575352