Classloader problem

16 views
Skip to first unread message

hbf

unread,
Aug 13, 2010, 6:00:18 AM8/13/10
to Google Web Toolkit
Hi everybody,

I am using the Apache Tika libraries [1] in my GWT project. All JUnit
test pass fine but in hosted mode, Tika does not find any parsers.
I've checked the source and see that they use the ServiceRegistry [2]
to find parsers, and in hosted mode, none are found.

When I put the Tika JARs into project/war/WEB-INF/lib/, Tika finds all
parsers in hosted mode, but I am not so happy with this as I am using
Maven to manage dependencies (and mvn eclipse:eclipse together with
the GWT Eclipse Plugin).

Tika offers me to pass a class loader to the ServiceRegistry. Is there
a way I can find a suitable class loader?
I have tried Thread.currentThread().getContextClassLoader() (the
standard one) and its parent without success.

Any ideas?

Thanks in advance,
Kaspar

[1] http://tika.apache.org/download.html, version 0.8-SNAPSHOT
[2] http://download.oracle.com/javase/1.4.2/docs/api/javax/imageio/spi/ServiceRegistry.html

Thomas Broyer

unread,
Aug 13, 2010, 6:35:17 AM8/13/10
to Google Web Toolkit

On 13 août, 12:00, hbf <kaspar.fisc...@dreizak.com> wrote:
> Hi everybody,
>
> I am using the Apache Tika libraries [1] in my GWT project. All JUnit
> test pass fine but in hosted mode, Tika does not find any parsers.
> I've checked the source and see that they use the ServiceRegistry [2]
> to find parsers, and in hosted mode, none are found.
>
> When I put the Tika JARs into project/war/WEB-INF/lib/, Tika finds all
> parsers in hosted mode, but I am not so happy with this as I am using
> Maven to manage dependencies (and mvn eclipse:eclipse together with
> the GWT Eclipse Plugin).

See http://code.google.com/eclipse/docs/faq.html#gwt_with_maven

cokol

unread,
Aug 13, 2010, 6:40:14 AM8/13/10
to Google Web Toolkit
hi, when you put something into WEB-INF/lib folder, the library is
loaded to the classpath of the servlet container regardless if its on
eclipse classpath or not. if you dont want to roll out the library
with the war file or it resides somewhere else than WEB-INF/lib - you
can still add the jar to eclipse classpath manually, so just do it.

you can also put this special jar on servlet container's classpath
when starting it, do it from a context menu on the root project ->
Run... -> Run As... then ensure "Google Web Toolkit" is selected on
the right menu and choose the "Classpath" tab on the right window
panel, then add the jar there manually and click "Run"
> [2]http://download.oracle.com/javase/1.4.2/docs/api/javax/imageio/spi/Se...

hbf

unread,
Aug 13, 2010, 8:48:35 AM8/13/10
to Google Web Toolkit
I added the two libraries to the "Classpath" tab (under "Bootstrap
Entries") and this works like a charm!

Thanks for your help, cokol and Thomas!
Kaspar

hbf

unread,
Aug 16, 2010, 5:50:08 AM8/16/10
to Google Web Toolkit
Unfortunately, just adding these two libraries (see previous post) did
not do the trick. Tika uses a lot of other libraries (for extraction
from PDF files, etc.) and classes from the latter libraries are not
found due to the class loader configuration.

What did work for me is to add the following line somewhere in the
startup code (in the servlet context listener in my case):


Parser.class.isAssignableFrom(Class.forName("org.apache.tika.parser.asm.ClassParser"));

Without this,

final Iterator<Parser> it =
ServiceRegistry.lookupProviders(org.apache.tika.parser.Parser.class);
while (it.hasNext())
{
System.err.println(it.next().getClass());
}

produces no results; with the above line, I see all parsers from Tika.
(ClassParser is one such parser. It was not enough to simply define a
ClassParser instance "ClassParser dummy".)

Kaspar
Reply all
Reply to author
Forward
0 new messages