Christopher,
Thanks so much for your help. I've been digging into this and with your
help, I've made some real progress. I've made additional comments below.
On 9/11/13 9:36 AM, Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
George,
On 9/10/13 6:34 PM, George S. wrote:
On 9/10/13 3:14 PM, Christopher Schultz wrote:
----- Is there a way that I can specify something in the
server.xml code that would register them? The only thing I can
see is to create a org.apache.catalina.LifecycleListener and put
the code to register the plugins in there.
Is there some other way of doing it? How would you do it if you
weren't running under Tomcat?
I only ever run Java with tomcat (or maybe ant), so I wouldn't
know.
Okay. I had never heard of an "imageio plugin" before. Are you
basically registering file-type handlers?
I'm just guessing at all of this, since I've never done anything
besides use ImageIO for mundane operations like loading, saving, and
re-sizing images.
I'm doing an auto-thumbnailer which resizes images. I've run into
problems with some files. For example, some Adobe JPGs are stored with a
color space of CYMK, or YCCK, which the default Java ImageIO code does
not handle correctly. The TwelveMonkeys plugin registers a handler that
is more complete and overrides the default behavior.
Similarly, I'm using PDFBox to thumbnail PDF images. It's been having
problems if the PDFs have JBIG2 encoded images in there since the Java
ImageIO stuff doesn't handle JBIG2. The Levigo JBIG2 library is for that.
Have you called ImageIO.scanForPlugins()?
The documentation gives light detains on how the plug-ins are found:
http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html#scanForPlugins%28%29
No, I wasn't calling that. I just tested it, and that does work. I'll
make suggestions to the library providers that reference that. I
honestly did search around a lot and found posts that referenced
manually registering them which is the direction I went.
I've got more comments below about why I think this works when from
reading the doc strictly, it should not be necessary.
What version of Java are you using?
I've tried with Oracle 1.7.0 U 25 on x64 Linux. I was also using 1.6.0 U
29 on x64 Linux
Perhaps you have to place youe plugins under an "endorsed"
directory (i.e. one specified via JAVA_ENDORSED_DIRS environment
variable when using Tomcat startup scripts).
- -chris
Well, I think this is how it's "supposed" to be done. However, the
jar's internal getResourceAsStream() function is failing when it's
trying to load properties that are built into the jar. This is
being tested without a security manager. It looks like being run
in java.endorsed.dirs is breaking the classloader. I did some
research, and it looks like java.endorsed.dirs runs in Tomcat's
Bootstrap classloader. The comments in the class loader howto don't
make me optimistic that I could make this work.
I think I'm just going to follow through on my original idea of
using a PluginLoader as a LifecycleListener
You probably don't have to do this. Just make sure that your JAR file
has all the resources in the right place(s) and it "should" work.
Testing outside of Tomcat should be easy: just write a small harness
that tries to e.g. load an image of one of those exotic types that the
JVM doesn't already recognize, and make sure that CLASSPATH is correct
when running it. If that works, it should work in Tomcat, too, since
the ClassLoader should always be the WebappClassLoader, whose resource
list includes all JAR files in WEB-INF/lib and all files rooted in
WEB-INF/classes
I had the libraries in the $CATALINA_BASE/lib directory, and I would
have expected them to work. I think in a more regular environment (only
one classloader) everything would work seamlessly. WEB-INF/lib is a
problem because I run hundreds of contexts all referencing the same code.
From looking at the tomcat classloader howto doc, here's what I think
was happening. My understanding may be wrong, but again it's based on
reading the classloader howto. I'm thinking that ImageIO is scanning
for plugins when the System classloader is initialized. The plugin jar
files that I was attempting to use were in $CATALINA_BASE/lib, which is
the common classloader. Essentially, when I make the call to
scanForPlugins(), a whole new classpath (common) is online, and that's
why it works.
This means my whole "plugin-loader" strategy is not really necessary. I
just have to get scanForPlugins() called once. In a way, this kind of
raises a question. I've read the docs on "ServiceLoader" here:
http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html
The imageio plugins are exactly a case and I'm thinking that
scanForPlugins() does a ServiceLoader.reload().
I guess the question in my mind is there a way that tomcat could
generically note any META-INF/services entries and ensure the proper
think is done to get those services loaded?
--
George Sexton
MH Software, Inc.
303 438-9585
http://www.mhsoftware.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org