Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO jboss EAP 6

We are using the JBoss EAP 6; Everything works well till production environment. But Post deployment in production, we are getting the below error:

java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO 

The error happening in one of the servlet where we are creating the Captcha. This is the line where this error is happening :

ImageIO.write(bufferedImage, "png", baos); 

Here is the stack trace for the Error :

Server:server-three] Caused by: java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO
[Server:server-three]   at org.fwcms.tc.servlet.Captcha.doGet(Captcha.java:150) [classes:]
[Server:server-three]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec.jar:1.0.2.Final-redhat-1]
[Server:server-three]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec.jar:1.0.2.Final-redhat-1]
[Server:server-three]   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb.jar:7.2.2.Final-redhat-1]
[Server:server-three]   ... 36 more

This is not happening any other environments. We are deploying the app as ear. Any suggestion/pointers in resolving this will help me a lot.

Thank you in advance.

Regards, Manjunath

like image 234
Manjunath Avatar asked Nov 02 '22 08:11

Manjunath


1 Answers

I found solution. You have to inicializate ImageIO before other operations. You can do this by adding:

static {
        ImageIO.scanForPlugins();
}

eg into your Main class.

like image 198
Lukas Adamek Avatar answered Nov 15 '22 03:11

Lukas Adamek