-
-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImageIO.getImageWriter(reader) not working inside tomcat #16
Comments
I guess you have already tried, but if not, restart Tomcat. :-) Are your using the same JRE for both Tomcat and the standalone app? Other than that, it's quite hard to tell what's going on without access to the Tomcat server. I assume when you say "inside a tomcat webapp" you mean a Servlet or Filter? If not, please describe how... My best suggestion is to use a debugger, and step through the code (both in Tomcat and the standalone app), to see what's going on, and look for any differences. |
Just a quick follow-up: I looked at the source code for It contains the following code (JDK 1.7.0u45 source):
For some reason (a bad one?) it uses the system class loader, and it will never have access to the web app local classes/JARs. You should probably file a bug against the Java class libraries on this. The workaround is to manually look it up, using code similar to what ImageIO uses, but use the context class loader ( Alternatively, add JARs to Tomcats shared or common libs folder, that might help. |
Using the context class loader in a custom method solved the issue, thanks! It look like a JDK issue, but opening bugs with them is like tilting at windmills :-) |
CD added sign profile
If, like me, you are still stumbling upon this old issue, and wonder what the best fix/workaround is these days:
servletContext.addListener(IIOProviderContextListener.class); of course with the following import: import com.twelvemonkeys.servlet.image.IIOProviderContextListener; With this, the standard ImageIO classes just work and you do not have to manually load any classes. I hope this helps. |
It would be great if @kkofler 's solution could be added to the documentation, because I think it costs people some time to find this... |
@stephanie-dm It certainly can! 😀 Why not create a PR against -- |
Hello Harald,
I wrote a basic test code that does work in a standalone test class:
public class Test
{
}
The same code doesn't work inside a tomcat webapp, writer is null so an exception is thrown.
I have:
I have verified with a test loop that the ImageWriter is loaded:
And the result:
logs/catalina.out:ImageIO, looking for writers
logs/catalina.out:ImageIO writer: class com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriter
logs/catalina.out:ImageIO writer: class com.sun.imageio.plugins.jpeg.JPEGImageWriter
Any idea about why is not working just inside tomcat? How to debug further?
Thanks,
Daniele.
The text was updated successfully, but these errors were encountered: