5

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

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
Manjunath
  • 172
  • 1
  • 2
  • 18
  • 1
    have you made sure that ClassPath Env variables are in sync in production or check if there is anything that is overriding Classpath environment variable. – Vivek Vermani Dec 26 '13 at 18:45
  • Do you have a full stackstrace so that we can see where the call is happening? – Philippe Marschall Dec 26 '13 at 23:32
  • Added the required stacktrace Philippe. Let me know if you need any further details. – Manjunath Dec 27 '13 at 03:46
  • Hello Vivek, how can I check whether anything is overriding the classpath env? – Manjunath Dec 27 '13 at 03:47
  • Since this is a `NoClassDefFoundError` and not a `ClassNotFoundError` something bad is happening when `ImageIO` is being instantiated. See this answer http://stackoverflow.com/questions/7325579/java-lang-noclassdeffounderror-could-not-initialize-class-xxx – disrvptor Dec 27 '13 at 03:54
  • I had the same problem (but not with JBoss) and I had jai_imageio.jar in classpath. Removing it solved the issue. – pvorb Aug 04 '14 at 09:40

1 Answers1

2

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.

Lukas Adamek
  • 111
  • 1
  • 7
  • thanks, especially the hint: "initialize before other operations" was extremely important for me (using PDFBOX in Java with PDImageXObject) – leole Nov 13 '18 at 07:32