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

Manjunath picture Manjunath · Dec 26, 2013 · Viewed 9.2k times · Source

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

Answer

Lukas Adamek picture Lukas Adamek · Feb 11, 2016

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.