placement of non-plugin utility classes

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

placement of non-plugin utility classes

Ben.BigHair
Hello,

I am trying to reconcile what I learned in a recent Java training course
with what I am learning about ImageJ.  One piece that is quite fuzzy in
my mind is the placement of my own non-plugin utility classes.  Suppose
I had a utility class, "MyArrayUtilityClass",that works with arrays in
some generic way (other examples might be string or file utilities)  .
  Where in the world do I put it so I can import it for my own ImageJ
plugins.  Literally, where do I place the class relative to the ImageJ
application and what does the import statement look like?

Cheers,
Ben
Reply | Threaded
Open this post in threaded view
|

Re: placement of non-plugin utility classes

Wayne Rasband
> Hello,
>
> I am trying to reconcile what I learned in a recent Java training
> course with what I am learning about ImageJ.  One piece that is quite
> fuzzy in my mind is the placement of my own non-plugin utility
> classes.  Suppose I had a utility class, "MyArrayUtilityClass",that
> works with arrays in some generic way (other examples might be string
> or file utilities)  .  Where in the world do I put it so I can import
> it for my own ImageJ plugins.  Literally, where do I place the class
> relative to the ImageJ application and what does the import statement
> look like?

To avoid class name conflicts, utility classes should be in packages.
There is an example at

      http://rsb.info.nih.gov/ij/plugins/packages.html

Utility classes and JAR files go in the plugins folder.

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

Re: placement of non-plugin utility classes

ctrueden
In reply to this post by Ben.BigHair
Hi Ben,

If you have a utility class that you want to access from a single plugin,
you can package with that plugin in a JAR file. If more than one of your
plugins needs it, you can place it in the jre/lib/ext on Windows or Linux,
or /Library/Java/Extensions on Mac OS X. Then you should be able to access
it as normal (if it is packageless, without an import statement, otherwise
importing the proper package).

Alternately, you might be able to use ImageJ's PluginClassLoader, but I
haven't experimented with that much.

-Curtis

On 7/11/06, Ben Tupper <[hidden email]> wrote:

>
> Hello,
>
> I am trying to reconcile what I learned in a recent Java training course
> with what I am learning about ImageJ.  One piece that is quite fuzzy in
> my mind is the placement of my own non-plugin utility classes.  Suppose
> I had a utility class, "MyArrayUtilityClass",that works with arrays in
> some generic way (other examples might be string or file utilities)  .
>   Where in the world do I put it so I can import it for my own ImageJ
> plugins.  Literally, where do I place the class relative to the ImageJ
> application and what does the import statement look like?
>
> Cheers,
> Ben
>
Reply | Threaded
Open this post in threaded view
|

Re: placement of non-plugin utility classes

Wayne Rasband
> If you have a utility class that you want to access from a single
> plugin,
> you can package with that plugin in a JAR file. If more than one of
> your
> plugins needs it, you can place it in the jre/lib/ext on Windows or
> Linux,
> or /Library/Java/Extensions on Mac OS X. Then you should be able to
> access
> it as normal (if it is packageless, without an import statement,
> otherwise
> importing the proper package).
>
> Alternately, you might be able to use ImageJ's PluginClassLoader, but I
> haven't experimented with that much.

ImageJ's PluginClassLoader automatically searches JAR files in the
plugins folder or immediate subfolders. Utility classes should always
be in a package to avoid class name conflicts.

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

Re: placement of non-plugin utility classes

Ben.BigHair
Wayne Rasband wrote:

>> If you have a utility class that you want to access from a single plugin,
>> you can package with that plugin in a JAR file. If more than one of your
>> plugins needs it, you can place it in the jre/lib/ext on Windows or
>> Linux,
>> or /Library/Java/Extensions on Mac OS X. Then you should be able to
>> access
>> it as normal (if it is packageless, without an import statement,
>> otherwise
>> importing the proper package).
>>
>> Alternately, you might be able to use ImageJ's PluginClassLoader, but I
>> haven't experimented with that much.
>
> ImageJ's PluginClassLoader automatically searches JAR files in the
> plugins folder or immediate subfolders. Utility classes should always be
> in a package to avoid class name conflicts.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: placement of non-plugin utility classes

Ben.BigHair
In reply to this post by Wayne Rasband
Wayne Rasband wrote:

>> Hello,
>>
>> I am trying to reconcile what I learned in a recent Java training
>> course with what I am learning about ImageJ.  One piece that is quite
>> fuzzy in my mind is the placement of my own non-plugin utility
>> classes.  Suppose I had a utility class, "MyArrayUtilityClass",that
>> works with arrays in some generic way (other examples might be string
>> or file utilities)  .  Where in the world do I put it so I can import
>> it for my own ImageJ plugins.  Literally, where do I place the class
>> relative to the ImageJ application and what does the import statement
>> look like?
>
> To avoid class name conflicts, utility classes should be in packages.
> There is an example at
>
>      http://rsb.info.nih.gov/ij/plugins/packages.html
>
> Utility classes and JAR files go in the plugins folder.
>

Hi,

This works very easily. I have a follow-up question.  But first I should
describe what I have done so far.

I can get the following plugin
        ImageJ/plugins/Ben/myPlugin_.class

to work with
        ImageJ/plugins/Ben/benutil/myUtility.class

using the package declarations and syntax like in the example...

package benutil;
        <other stuff>
someResult = benutil.myUtility.myMethod();


I was thinking that I could place the utility class in the
        ImageJ/plugins/Utilities/myUtility.class

That would change the package and method call to

package Utilities;
        <other stuff>
someResult = Utilities.myUtility.myMethod();

But myUtility.class is not found when I run
        ImageJ/plugins/Ben/myPlugin_.class

It seems that the package has to reside within the directory (or
subdirectory) where myPlugin.class resides.

So my question what is the conventional organization of projects within
the ImageJ/plugins/ so that utility classes are universally accessible?

Thanks and cheers,
Ben
Reply | Threaded
Open this post in threaded view
|

Re: placement of non-plugin utility classes

Wayne Rasband
Utility classes should be packaged as a JAR file. Such JAR files can be
placed in the Plugins folder or any immediate sub-folder. If the
utility class is in the benutil package then the it needs to be in a
benutil directory in the JAR file.

-wayne

> This works very easily. I have a follow-up question.  But first I
> should describe what I have done so far.
>
> I can get the following plugin
> ImageJ/plugins/Ben/myPlugin_.class
>
> to work with
> ImageJ/plugins/Ben/benutil/myUtility.class
>
> using the package declarations and syntax like in the example...
>
> package benutil;
> <other stuff>
> someResult = benutil.myUtility.myMethod();
>
>
> I was thinking that I could place the utility class in the
> ImageJ/plugins/Utilities/myUtility.class
>
> That would change the package and method call to
>
> package Utilities;
> <other stuff>
> someResult = Utilities.myUtility.myMethod();
>
> But myUtility.class is not found when I run
> ImageJ/plugins/Ben/myPlugin_.class
>
> It seems that the package has to reside within the directory (or
> subdirectory) where myPlugin.class resides.
>
> So my question what is the conventional organization of projects
> within the ImageJ/plugins/ so that utility classes are universally
> accessible?
>
> Thanks and cheers,
> Ben
>