Login  Register

Re: Path Problem?

Posted by Stephan Saalfeld on Jan 19, 2010; 5:06pm
URL: http://imagej.273.s1.nabble.com/Path-problem-tp3689668p3689672.html

It seems that either Java or ImageJ show us their ugly face here ;)

The path matters!  Never thought about this because I always followed
the main stream and did that...

If test_1 is in package my_stuff, it also has to be in a folder my_stuff
respectively.  The content of your jar must thus be minimally:

$ jar -vtf Test_.jar
   471 Tue Jan 19 17:58:14 CET 2010 my_stuff/test_1.class
   132 Tue Jan 19 17:40:20 CET 2010 plugins.config


Add the source if you like.  The jar must have an underscore in its name
for announcing itself as a plugin to ImageJ (e.g. Test_.jar)

In your example, the package declaration was missing thus the code
should be:

$ cat my_stuff/test_1.java
package my_stuff;

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;

public class test_1 implements PlugIn {

public void run(String arg) { shared_method(); }

  public void shared_method() { IJ.showMessage("test_1","Hello world!");
}
}

I compiled that with:

$ javac -cp /wherever/you/have/imagej/ij.jar my_stuff/*.java

then

$ jar cvfM Test_.jar my_stuff/* plugins.config

Runs for me.

Best,
Stephan



On Tue, 2010-01-19 at 09:36 -0600, Bob wrote:

> Stephan,
>
> You're right, of course, I should have used a new in my test_2.java example
> (it is in the original code, but didn't survive when I rewrote the
> simplified illustration).  But where I'm stuck is at the point before test_2
> enters the picture.  Basically, I can't get experiment 2 (which only
> involves the packaged version of test_1) to work.  You're also correct that
> this may be a Java problem, not an ImageJ problem, since I'm new to both.
> To focus a bit more clearly on my current stopper, this fails:
>
> test_1.java:
> package my_stuff;
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.*;
>
> public class test_1 implements PlugIn {
>
>  public void run(String arg) { shared_method(); }
>
>  public void shared_method() { IJ.showMessage("test_1","Hello world!"); }
> }
>
>
> plugins.config:
>
> # Name: Test_Plugin
>
> # Author: Bob
> # Version: 1.0
> # Date: 1/18/10
> # Requires: ImageJ 1.31s
>
> Plugins>Test, "Test 1", my_stuff.test_1("run")
>
> The issue may be in the way I compile, by just using the "Compile and
> Run..." in ImageJ to generate test_1.class, and then manually making the
> .jar file using "jar cvfM Test.jar test_1.class test_1.java plugins.config".
> However, it seems more likely to me that I have the syntax wrong in the last
> line of plugins.config.  The error message I am getting is:  "Plugin or
> class not found: 'my_stuff.test_1' (java.lang.ClassNotFoundException:
> my_stuff.test_1)"
>
>
> > Your problems are on Java syntax, not ImageJ ;)---read:
> >
> > http://java.sun.com/docs/books/tutorial/java/index.html
> >
> > I your case, what you're trying is to use an instance method in a static
> > way.  In Java, an object is not instantiated just by declaring it, you
> > have to use new.  So either:
> >
> > test_1.java:
> >
> > public class test_1 implements PlugIn {
> >
> > public void run(String arg) { shared_method(); }
> >
> > static public void shared_method() { IJ.showMessage("test_1","Hello
> > world!"); }
> > }
> >
> > or leaving test_1 as you had it before:
> >
> > test_2.java:
> >
> > public class test_2 implements PlugIn {
> >
> > public void run(String arg) {
> >     test_1 temp = new test_1();
> >     temp.shared_method();
> >   }
> >
> > }
> >
> > The previous test_1/test_2 combination shouldn't have been compilable.
> >
> > Best,
> > Stephan