ImageJ startup and CLASSPATH

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ImageJ startup and CLASSPATH

Johannes Hermen
We are working on a DICOM plugin for ImageJ which requires some additional
libraries (jar-files) in the ImageJ CLASSPATH.

Most of the other plugins who need additional libraries, equip their
plugins with a own ImageJ startup-script which sets this CLASSPATH.
The problem is, that if you install some of these plugins, you have to
edit the startup-script to add all nessessary files to the CLASSPATH.

To make the CLASSPATH handling a bit easier, we wrote a small
"runImagej.jar" file which starts the ImageJ program with all library
files in the "lib/" directory in its CLASSPATH.

I Just wanted to ask if you know any better solution to solve this
problem, or if you think this small starter application is a good way to
solve this problem.

Greets from Luxembourg

        Johannes Hermen
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ startup and CLASSPATH

Johannes Hermen
MESSAOUDI Cédric <[hidden email]> wrote on 03.11.2005 09:53:58:

The problem is, that all the the external libraries are allready
jar-files, and it is not possible to pack a jar-file into another
jar-file.
One solution would be to unpack all the libraries and pack them again into
one big jar-file, but this is not a nice way of doing this, and it will
not work on signed libraries or because of licensing issues.

But thanks for your response.

        Johannes Hermen

>
> Can't you just compile your plug-in as a jarfile with your libraries
inside?

>
> It should do the same thing, and if 2 plug-ins tries to load the same
> library from 2 locations, java only keeps the first one if I remember
> correctly.
>
> It should be simpler for the installation of plug-ins too.
>
> Cedric MESSAOUDI
> -----Message d'origine-----
> De : ImageJ Interest Group [mailto:[hidden email]] De la part de
> Johannes Hermen
> Envoyé : jeudi 3 novembre 2005 09:10
> À : [hidden email]
> Objet : ImageJ startup and CLASSPATH
>
> We are working on a DICOM plugin for ImageJ which requires some
additional

> libraries (jar-files) in the ImageJ CLASSPATH.
>
> Most of the other plugins who need additional libraries, equip their
> plugins with a own ImageJ startup-script which sets this CLASSPATH.
> The problem is, that if you install some of these plugins, you have to
> edit the startup-script to add all nessessary files to the CLASSPATH.
>
> To make the CLASSPATH handling a bit easier, we wrote a small
> "runImagej.jar" file which starts the ImageJ program with all library
> files in the "lib/" directory in its CLASSPATH.
>
> I Just wanted to ask if you know any better solution to solve this
> problem, or if you think this small starter application is a good way to

> solve this problem.
>
> Greets from Luxembourg
>
>         Johannes Hermen
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ startup and CLASSPATH

Wayne Rasband
In reply to this post by Johannes Hermen
> We are working on a DICOM plugin for ImageJ which requires
> some additional libraries (jar-files) in the ImageJ
> CLASSPATH.
>
> Most of the other plugins who need additional libraries,
> equip their plugins with a own ImageJ startup-script which
> sets this CLASSPATH. The problem is, that if you install
> some of these plugins, you have to edit the startup-script
> to add all nessessary files to the CLASSPATH.
>
> To make the CLASSPATH handling a bit easier, we wrote a
> small "runImagej.jar" file which starts the ImageJ program
> with all library files in the "lib/" directory in its
> CLASSPATH.
>
> I Just wanted to ask if you know any better solution to
> solve this problem, or if you think this small starter
> application is a good way to solve this problem.

There is no need for another starter application. Try adding the JAR
files to the ImageJ plugins directory, or sub-directory. ImageJ's
PluginClassLoader can load classes from JAR files located in the
plugins directory. If that doesn't work, try adding the JAR files to
Java extension directory, ..\ImageJ\jre\lib\ext on Windows and Linux,
or /System/Library/Java/Extensions on Mac OS X.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ startup and CLASSPATH

Johannes Hermen
Hi Wayne

ImageJ Interest Group <[hidden email]> wrote on 03.11.2005 16:33:56:
> There is no need for another starter application. Try adding the JAR
> files to the ImageJ plugins directory, or sub-directory. ImageJ's
> PluginClassLoader can load classes from JAR files located in the
> plugins directory.

I just tried it that way, but i get a "class not found" Exception from
inside one of my used external libraries.
This is the part of the code that throws the Exception:
---------
public static Object findFactory(String key) {
        ClassLoader loader =
Thread.currentThread().getContextClassLoader();
        String name = rb.getString(key);
        try {
            return loader.loadClass(name).newInstance();
        } catch (ClassNotFoundException ex) {
            throw new ConfigurationError("class not found: " + name, ex);
        } catch (InstantiationException ex) {
            throw new ConfigurationError("could not instantiate: " + name,
ex);
        } catch (IllegalAccessException ex) {
            throw new ConfigurationError("could not instantiate: " + name,
ex);
        }
   }
---------
could this be a problem with your classloader, because it works if the
libraries are in the normal java CLASSPATH?

It would be really cool if this solution would work.

>If that doesn't work, try adding the JAR files to
> Java extension directory, ..\ImageJ\jre\lib\ext on Windows and Linux,
> or /System/Library/Java/Extensions on Mac OS X.

This solution works, but is not really an option to us. Some of our users
work on Linux and Windows systems without admin-rights and are unable to
place the files in the extension directory. Another problem is that this
solution makes it impiossible to have different versions of the same
libraries for different applications.


Thanks for your help

        Johannes Hermen