Re: [Ikvm-developers] trying to set classloader without app.config
Brought to you by:
jfrijters
From: Jeroen F. <je...@su...> - 2011-11-02 12:01:51
|
Hi, It's probably a little bit better to use: Thread.currentThread().setContextClassLoader(ikvm.runtime.AssemblyClassLoader.getAssemblyClassLoader(Assembly.Load("Tika"))); That way you don't get the additional AssemblyClassLoader instance. Regards, Jeroen > -----Original Message----- > From: Craig Main [mailto:cr...@pa...] > Sent: Wednesday, November 02, 2011 12:04 > To: Jeroen Frijters > Cc: ikv...@li... > Subject: Re: [Ikvm-developers] trying to set classloader without > app.config > > Hi, > > I solved it with your advice. I am so pleased. > > java.lang.Thread.currentThread().setContextClassLoader(new > Tika.MySystemClassLoader(new > ikvm.runtime.AssemblyClassLoader(Assembly.Load("Tika")))) > > That does the trick. > > It also works without the custom class loader. This also does the trick. > java.lang.Thread.currentThread().setContextClassLoader(new > ikvm.runtime.AssemblyClassLoader(Assembly.Load("Tika"))); > > Regards > Craig. > > On Wed, Nov 2, 2011 at 10:03 AM, Jeroen Frijters <je...@su...> > wrote: > > > Hi, > > The Java class loader model is based on a global class loader (or > thread local, but that still bad) and insufficient information to load > the "right" class (i.e. just the class name), so there will always be > friction between that and the .NET world (although Java 8 is supposed to > get module support, which will improve things a bit). > > When you tried > ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("Tika")), did > Tika.dll contain *all* the required classes or are there other (dyanmic) > dependencies? If there are other dependencies, you should also add > those. > > You can also try using Thread.setContextClassLoader(), but it > depends on the Tika code to actually use the thread context class > loader. > > Regards, > Jeroen > > > > -----Original Message----- > > From: Craig Main [mailto:cr...@pa...] > > Sent: Wednesday, November 02, 2011 07:55 > > To: ikv...@li... > > Subject: [Ikvm-developers] trying to set classloader without > app.config > > > > Hi, > > > > I am using Tika in .NET > > > http://blogs.dovetailsoftware.com/blogs/kmiller/archive/2010/07/02/using > > -the-tika-java-library-in-your-net-application-with-ikvm > > > > I have followed the instructions there carefully, and created a > custom > > classloader that inherits java.lang.ClassLoader. > > If I include this in my app.config the Tika application loads all > the > > necessary classes correctly. I wish to achieve the same result > without > > an app.config file entry. > > > > Trying this in the library does not seem to work. > > Perhaps this needs to be in the application, rather than in the > library? > > I would rather keep the library self contained, but this does not > seem > > possible. > > > > [assembly: > > > IKVM.Attributes.CustomAssemblyClassLoader(typeof(Tika.MySystemClassLoade > > r))] > > Tika is the wrapper dll. I have also tried > > > ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("Tika")); > > In my application which does not seem to work. I am not sure why > the > > relevant classes cannot be loaded without a custom class loader. > My java > > is so rusty these days. > > Is there a way (in code) to set the class loader in the > application > > before calling the library to ensure that the classloader works. > Better > > still would be to be able to include the necessary code in the > wrapper > > dll. > > Thanks > > Regards > > Craig. > > |