In 2 previous blog posts, my colleague Daniel wrote about finding a memory leak in the Java JPEG2000 library and the source code change. I have been looking at another bug so I thought a series of articles on the subject would be of interest.
To use JPEG2000 images in Java, you need to use some additional libraries. These seem to have been abandoned by Oracle but luckily you can still get the source code to debug. This article is about how to get the source code and set it up to run in an IDE (I have used Eclipse as an example);.
Downloading the source
The first step is to get the Java code.
You can download the source code from Oracle with this command
svn co https://svn.java.net/svn/jai-imageio-core~svn
Don’t forget to include Daniel’s patch for the memory leak which you can get here.
Set the source as your src
The SVN repositry actually contains not only the source code bu also jars needed to run the code and build tools. The source code for the actual JPEG2000 plugin is hidden in trunk/src/share/classes – we added a link to this so we could preserve the SVN structure and still have the correct package locations. You will also need the 2 JAI jars (jai_core.jar and jai_codec.jar) and trunk/src/share/jc4libjai/clibwrapper_jiio.jar to compile the source.
Hacking the source to run
To get the code to run, I found that I had to hack the PackageUtil class. Once you have downloaded and configured the project, hack the vendor code in the package com.sun.media.imageioimpl.common.PackageUtil.java by setting version and vendor details as you can see in this screenshot.
The actual JPEG2000 code is mainly found in jpeg2000 library plug-ins can be found in the package called com.sun.media.imageioimpl.plugins.jpeg2000; I will be looking at this in more detail in later articles…
Now you are ready to start hacking the code!