classpath and importing

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

classpath and importing

Tony Shepherd
I'm writing a plugin. The source code and class files are in
ImageJ/plugins/myplugin/

The source code includes several
'import ij.*;'
'import ij.something.*;'
and everything compiles fine.

Now I create a directory at the same level as 'ij' and 'plugins'
(i.e. ../../../ImageJ/mydirectory/)

I move some of my own java source (and compiled class) files into
'mydirectory', but not the main one, which still should be compiled from
inside 'plugins'

I include the line 'import mydirectory.*;' at the beginning of the main
plugin source code

The plugin will not compile as the package 'mydirectory' is not found. Can
anyone tell me why/what to do?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: classpath and importing

ctrueden
Hi Tony,

Your problem is a Java class path issue.

First of all, for your java source in 'mydirectory', did you declare
them as "package mydirectory;" within the source? If not, you cannot
use import to reference them in that fashion, since 'import
mydirectory.*' is a shortcut for references classes from the
'mydirectory' package -- not necessarily within a folder called
'mydirectory'.

Secondly, in order for your code to consider the folder 'mydirectory'
as containing the package 'mydirectory', you must reference the proper
root folder as a class path root, either using the CLASSPATH
environment variable, the -cp command line flag to the Java compiler,
or the build path settings within whatever IDE you are using. In your
case, you would want the ImageJ folder itself to be part of your class
path.

You may want to read an overview of how Java class path works:
    http://en.wikipedia.org/wiki/Classpath_(Java)

If your development is getting complicated enough to start creating
packages, you may want to consider moving your codebase out of the
ImageJ folder structure completely into its own place, and creating a
build script (I recommend Ant) to compile your code and turn it into a
JAR library for you. Then you can distribute the JAR as an ImageJ
plugin. This also has the advantage of being able to specify a
plugins.config file to define exactly what appears in the ImageJ
Plugins menu.

-Curtis

On 9/17/07, Tony Shepherd <[hidden email]> wrote:

> I'm writing a plugin. The source code and class files are in
> ImageJ/plugins/myplugin/
>
> The source code includes several
> 'import ij.*;'
> 'import ij.something.*;'
> and everything compiles fine.
>
> Now I create a directory at the same level as 'ij' and 'plugins'
> (i.e. ../../../ImageJ/mydirectory/)
>
> I move some of my own java source (and compiled class) files into
> 'mydirectory', but not the main one, which still should be compiled from
> inside 'plugins'
>
> I include the line 'import mydirectory.*;' at the beginning of the main
> plugin source code
>
> The plugin will not compile as the package 'mydirectory' is not found. Can
> anyone tell me why/what to do?
>
> Thanks
>
Reply | Threaded
Open this post in threaded view
|

Re: classpath and importing

Tony Shepherd
Thanks Curtis, that really helps.

Things get better when I
  (i) put "package commonname;" at the top of all the source files
  (ii) moved 'mydirectory' inside the 'plugins' folder, where ImageJ already
looks for classes.

However, one problem remains because a couple of the classes inside this
package are interdependent (they use each other). If I don't have them as
part of the package they don't see each other, if I do then one class gives
a compile error like "class MyThing.class does not contain MyThing, instead
it contains mydirectory.MyThing".

I know this might be a general Java question not an ImageJ question, so I'll
understand if you leave it there.

Otherwise thanks,

Tony


>From: Curtis Rueden <[hidden email]>
>Reply-To: ImageJ Interest Group <[hidden email]>
>To: [hidden email]
>Subject: Re: classpath and importing
>Date: Mon, 17 Sep 2007 11:38:46 -0500
>
>Hi Tony,
>
>Your problem is a Java class path issue.
>
>First of all, for your java source in 'mydirectory', did you declare
>them as "package mydirectory;" within the source? If not, you cannot
>use import to reference them in that fashion, since 'import
>mydirectory.*' is a shortcut for references classes from the
>'mydirectory' package -- not necessarily within a folder called
>'mydirectory'.
>
>Secondly, in order for your code to consider the folder 'mydirectory'
>as containing the package 'mydirectory', you must reference the proper
>root folder as a class path root, either using the CLASSPATH
>environment variable, the -cp command line flag to the Java compiler,
>or the build path settings within whatever IDE you are using. In your
>case, you would want the ImageJ folder itself to be part of your class
>path.
>
>You may want to read an overview of how Java class path works:
>     http://en.wikipedia.org/wiki/Classpath_(Java)
>
>If your development is getting complicated enough to start creating
>packages, you may want to consider moving your codebase out of the
>ImageJ folder structure completely into its own place, and creating a
>build script (I recommend Ant) to compile your code and turn it into a
>JAR library for you. Then you can distribute the JAR as an ImageJ
>plugin. This also has the advantage of being able to specify a
>plugins.config file to define exactly what appears in the ImageJ
>Plugins menu.
>
>-Curtis
>
>On 9/17/07, Tony Shepherd <[hidden email]> wrote:
> > I'm writing a plugin. The source code and class files are in
> > ImageJ/plugins/myplugin/
> >
> > The source code includes several
> > 'import ij.*;'
> > 'import ij.something.*;'
> > and everything compiles fine.
> >
> > Now I create a directory at the same level as 'ij' and 'plugins'
> > (i.e. ../../../ImageJ/mydirectory/)
> >
> > I move some of my own java source (and compiled class) files into
> > 'mydirectory', but not the main one, which still should be compiled from
> > inside 'plugins'
> >
> > I include the line 'import mydirectory.*;' at the beginning of the main
> > plugin source code
> >
> > The plugin will not compile as the package 'mydirectory' is not found.
>Can
> > anyone tell me why/what to do?
> >
> > Thanks
> >

_________________________________________________________________
Got a favourite clothes shop, bar or restaurant? Share your local knowledge  
http://www.backofmyhand.com
Reply | Threaded
Open this post in threaded view
|

Center of Arcs

Frederic V. Hessman
In case someone might need an algorithm designed to find the center of an image containing incomplete circular arcs:

        http://www.astro.physik.uni-goettingen.de/~hessman/ImageJ/Center_of_Arcs/

The original purpose was to find the opto-mechanical center of a Nasmyth telescope by rotating the image during an exposure, producing circular trails of stars. The plugin tries out several potential centers and calculates the mean of a sum of pixels at constant radii. For this purpose, it is advantageous to threshold and skeletonize the trails and so reduce them to their purest arcs, minimize the contribution of non-arc features. The peak of the resulting map gives the coordinates of the best center.   See the above link for an example.

Rick