背景

springmvc应用最近从windows迁移到ubuntu18.04,前端验证码无法加载,后来看控制台报以下错误

2020-08-06 15:49:49,983 ERROR [500.jsp] - Could not initialize class javax.imageio.ImageIO
java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO
        at com.google.code.kaptcha.servlet.KaptchaServlet.init(KaptchaServlet.java:50)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
        at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

前端现象:

 

 这个出错原因比较简单,因为linux是非图形界面启动,没加载相关图形函数库,绘制验证码的过程中报错了,最早从事java工作的时候遇到过,那个博客(百度空间)无效了。

再次记录一下。

解决方法

#打开文件,添加JVM参数
vim apache-tomcat-8.0.11/bin/catalina.sh
#添加
JAVA_OPTS="-Djava.awt.headless=true -Dawt.toolkit=sun.awt.HToolkit"

如图

重启tomcat后如下

 

参考

https://stackoverflow.com/questions/22475739/could-not-initialize-class-javax-imageio-imageio

posted on 2020-08-06 16:02  你不知道的浪漫  阅读(2602)  评论(0编辑  收藏  举报