Not able to load javax.imageio.ImageIO class in WAS 8.5

有些话、适合烂在心里 提交于 2020-01-24 21:48:26

问题


I am not able to load ImageIO class of JAI 1.3.0. Java 6 and Web Application Server (WAS) 8.5. My code is working fine for Java 6 and WAS(7.0.19).

I have mentioned dependency properly in pom. Need to know if any one has same issue or not.

byte[] imgBytes = imagesVO.getImgBytes();
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imgBytes));

It seems my server is not able load ImageIO class during execution, hence image value is coming null. I am passing Tiff format file in imagesVO.


回答1:


There was a behavior change in WAS 8.5 regarding the ImageIO library, as part of some class loader leak prevention logic added in that release. When leak prevention is enabled, the ImageIO library is immediately instantiated as part of the server startup process, with the goal of preventing it from linking (permanently, since it's not friendly to the dynamic nature of Java EE class loading) to an application-provided implementation class. The side effect, though, is that since the library is instantiated before application classes are present, any application-provided plugins will fail to be located.

There are a few potential workarounds for this:

1) Explicitly call ImageIO.scanForPlugins() before you perform your operation. That will tell ImageIO to do a rescan for plugin classes using the thread context class loader, and yours will get picked up. Note that this is going to cause a permanent reference from the system-level ImageIO library to your application class, so the class loader will be leaked if you restart the application without restarting the JVM (this happened in previous WebSphere versions already, so this probably isn't a huge problem for you).

2) Disable the class loader leak prevention in your server. You can do this with a system property (com.ibm.ws.runtime.component.disableMemoryLeakService=true). The same caveat applies regarding the leakage of the class loader.

3) Add the necessary ImageIO library to your JVM class path. The situations that call for JVM-level class path modification are extremely few and far between, but this is one of them - ImageIO will scan for plugins during server startup, find your plugin (since it's in the JVM class path), and as a bonus it won't leak your application class loader.



来源:https://stackoverflow.com/questions/42840693/not-able-to-load-javax-imageio-imageio-class-in-was-8-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!