How to link an external package to plugin in ImageJ?

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

How to link an external package to plugin in ImageJ?

jiajian shen
Hi All,

Sorry to bother if you are not interested.  I want to do some matrix
operation by ImageJ plugin.  I import the package Jama.jar since it does a
lot matrix operation.  I downloaded it to ImageJ/jre/lib/Jama.jar, and I use
"import Jama.*" in the plugin head.  But the compiler told me that

"package Jama does not exist
import Jama.*; "

I think it is a link problem.  How to make the program knows where is the
package Jama?

Thanks a lot,
Jiajian
Reply | Threaded
Open this post in threaded view
|

Re: How to link an external package to plugin in ImageJ?

Sami Badawi-2
Hi Jiajian,

For mathematics I use commons-math-1.1.jar.

All you have to do is place all the needed jar files in ImageJ/plugin
and your PlugInFilter should be able to see it.

-Sami Badawi
http://www.shapelogic.org
Reply | Threaded
Open this post in threaded view
|

Antwort: Re: How to link an external package to plugin in ImageJ?

Joachim Wesner
Nope,

this is the problem me and others are  discussing now for some time,
compiled plugins will find any packages in the plugins directory and below,
but not the (built-in) compiler itself, because
it uses a different classloading mechanism. One way is to add the plugins
directory to the IJ classpath, but this still seems to leave some problems.

Is there any chance to have a general fix to this, so that compile-time and
run-time behavior wil be always the same?


Mit freundlichen Grüßen / Best regards

Joachim Wesner

____________________________________________

Leica Microsystems CMS GmbH | GmbH mit Sitz in Wetzlar | Amtsgericht
Wetzlar  HRB 2432
Geschäftsführer:  Dr. Stefan Traeger | Dr. Wolf-Otto Reuter | Dr. David Roy
Martyr | Colin Davis


                                                                           
             Sami Badawi                                                  
             <sami.badawi@GMAI                                            
             L.COM>                                                     An
             Gesendet von:              [hidden email]                
             ImageJ Interest                                         Kopie
             Group                                                        
             <[hidden email].                                       Thema
             GOV>                       Re: How to link an external        
                                        package to plugin in ImageJ?      
                                                                           
             28.01.2008 18:47                                              
                                                                           
                                                                           
              Bitte antworten                                              
                    an                                                    
              ImageJ Interest                                              
                   Group                                                  
             <[hidden email].                                            
                   GOV>                                                    
                                                                           
                                                                           




Hi Jiajian,

For mathematics I use commons-math-1.1.jar.

All you have to do is place all the needed jar files in ImageJ/plugin
and your PlugInFilter should be able to see it.

-Sami Badawi
http://www.shapelogic.org



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Antwort: Re: How to link an external package to plugin in ImageJ?

dscho
Hi,

On Mon, 28 Jan 2008, Joachim Wesner wrote:

> this is the problem me and others are discussing now for some time,
> compiled plugins will find any packages in the plugins directory and
> below, but not the (built-in) compiler itself, because it uses a
> different classloading mechanism. One way is to add the plugins
> directory to the IJ classpath, but this still seems to leave some
> problems.

You will have to add each .jar individually to the classpath.  Just adding
the folder where they live in is not enough.

Hth,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: How to link an external package to plugin in ImageJ?

J H-4
In reply to this post by Joachim Wesner
Yes, it does seem like the answer to this question depends on HOW you are
compiling your plugin.

With Jama.jar in your plugins folder:

1) if you are editing and compiling the plugin source outside of ImageJ, and
you call javac via the command line, you need to explicitly add the javac
parameter -classpath plugins/Jama.jar

2) if you edit and compile the plugin outside of imageJ and you are using
the ANT file build.xml, then you need to edit the compile tag to

 <javac srcdir="." classpath="plugins/Jama.jar" destdir="build"
optimize="on" source="1.4" target="1.4" debug="on">

3) If you are compiling using ImageJ "compile and run", then the the javac
that ImageJ calls will (line 73 of Compiler.java) inherit the system
classpath of the JVM that was used to run ImageJ.  So as Joachim said add
Jama.jar to the classpath of the java process that started ImageJ.  Although
(as discussed recently) this may cause problems.

The best way I can think of solving this?  If you hold down the ALT key when
clicking "Compile and Run" an options dialog appears (Line 40 Compiler.java).
It would be very easy to change this dialog to ask for an optional
classpath, and use it instead of or as well as the default classpath.

The code would look something like this:
Add to Compiler.java the member variable
  private static String extraClassPath;

In CompileAndRun(String path) add to read:
      if (IJ.altKeyDown()) {
            IJ.setKeyUp(KeyEvent.VK_ALT);
            GenericDialog gd = new GenericDialog("Compile and Run");
            gd.addCheckbox("Generate Debugging Info (javac -g)",
generateDebuggingInfo);
            gd.addStringField("Additional Classpath or jar library",
this.extraClassPath);
            gd.showDialog();
            if (gd.wasCanceled()) return;
            generateDebuggingInfo = gd.getNextBoolean();
            this.extraClassPath = gd.getNextString();
        }

In Compile( String path) edit to read:
if (generateDebuggingInfo)
            arguments = new String[] {"-g", "-deprecation", "-classpath",
classpath, path, this.extraClassPath};
        else
            arguments = new String[] {"-deprecation", "-classpath",
classpath, path, this.extraClassPath};

although you'll have to do it everytime you start imageJ, an improvement
would be to add it as a pref parameter as well.

This is off the top of my head, I haven't tried it, please don't sue if it
doesn't work.

On Jan 28, 2008 1:50 PM, Joachim Wesner <
[hidden email]> wrote:

> Nope,
>
> this is the problem me and others are  discussing now for some time,
> compiled plugins will find any packages in the plugins directory and
> below,
> but not the (built-in) compiler itself, because
> it uses a different classloading mechanism. One way is to add the plugins
> directory to the IJ classpath, but this still seems to leave some
> problems.
>
> Is there any chance to have a general fix to this, so that compile-time
> and
> run-time behavior wil be always the same?
>
>
> Mit freundlichen Grüßen / Best regards
>
> Joachim Wesner
>
> ____________________________________________
>
> Leica Microsystems CMS GmbH | GmbH mit Sitz in Wetzlar | Amtsgericht
> Wetzlar  HRB 2432
> Geschäftsführer:  Dr. Stefan Traeger | Dr. Wolf-Otto Reuter | Dr. David
> Roy
> Martyr | Colin Davis
>
>
>
>             Sami Badawi
>             <sami.badawi@GMAI
>             L.COM>                                                     An
>             Gesendet von:              [hidden email]
>             ImageJ Interest                                         Kopie
>             Group
>             <[hidden email].                                       Thema
>             GOV>                       Re: How to link an external
>                                        package to plugin in ImageJ?
>
>             28.01.2008 18:47
>
>
>              Bitte antworten
>                    an
>              ImageJ Interest
>                   Group
>             <[hidden email].
>                   GOV>
>
>
>
>
>
>
> Hi Jiajian,
>
> For mathematics I use commons-math-1.1.jar.
>
> All you have to do is place all the needed jar files in ImageJ/plugin
> and your PlugInFilter should be able to see it.
>
> -Sami Badawi
> http://www.shapelogic.org
>
>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>
Reply | Threaded
Open this post in threaded view
|

Re: How to link an external package to plugin in ImageJ?

Wayne Rasband
The "Compile and Run" command in ImageJ 1.39r automatically adds JAR
files (e.g., Jama.jar) in the plugins folder, or subfolder, to the
compiler's classpath. The name of the JAR file must end in ".jar" and
there can't be an underscore in the name. A preview of v1.39r is
available at <http://rsb.info.nih.gov/ij/ij.jar>.

-wayne

> Hi All,
>
> Sorry to bother if you are not interested.  I want to do some matrix
> operation by ImageJ plugin.  I import the package Jama.jar since
> it does a lot matrix operation.  I downloaded it to
> ImageJ/jre/lib/Jama.jar,
> and I use "import Jama.*" in the plugin head.  But the compiler told
> me that
>
> "package Jama does not exist
> import Jama.*; "
>
> I think it is a link problem.  How to make the program
> knows where is the package Jama?
>
> Thanks a lot,
> Jiajian
>
Reply | Threaded
Open this post in threaded view
|

Re: How to link an external package to plugin in ImageJ?

jiajian shen
Dear Wayne,

It does works and thanks a lot!  This helps me so much.

Sincerely,
Jiajian
On Jan 29, 2008 4:01 PM, Wayne Rasband <[hidden email]> wrote:

> The "Compile and Run" command in ImageJ 1.39r automatically adds JAR
> files (e.g., Jama.jar) in the plugins folder, or subfolder, to the
> compiler's classpath. The name of the JAR file must end in ".jar" and
> there can't be an underscore in the name. A preview of v1.39r is
> available at <http://rsb.info.nih.gov/ij/ij.jar>.
>
> -wayne
>
> > Hi All,
> >
> > Sorry to bother if you are not interested.  I want to do some matrix
> > operation by ImageJ plugin.  I import the package Jama.jar since
> > it does a lot matrix operation.  I downloaded it to
> > ImageJ/jre/lib/Jama.jar,
> > and I use "import Jama.*" in the plugin head.  But the compiler told
> > me that
> >
> > "package Jama does not exist
> > import Jama.*; "
> >
> > I think it is a link problem.  How to make the program
> > knows where is the package Jama?
> >
> > Thanks a lot,
> > Jiajian
> >
>