java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream 报错解决

报错的方法栈

在ssm中写了一个 utils 类,定义了main方法测试和查看工具实际数据
运行main方法时报错了,之前都没错,莫名其妙报了错

java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletOutputStream
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" 
解决办法

pom.xml 中引入的 servlet-api中定义了 <scope>provided</scope>,把这里的provided改成compile
java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream 报错解决

转载地址作者:https://www.cnblogs.com/zongJianKun/p/10956263.html

上一篇:java如何防止反编译


下一篇:14-ClassLoader源码分析与实例剖析