Discussion:
JNI
lakshmi
2012-05-30 15:43:08 UTC
Permalink
Hi,

I am trying to write plugins for fiji which uses native code. I am new
to this field and so I know very less about this.
In Fiji I went to the path File>New>Script and wrote the
Hello_World.java file:

import fiji.JNI;
import ij.IJ;
import ij.plugin.*;

public class Hello_World implements PlugIn {
static
{
JNI.loadlibrary("Hello_World");
}

native void sayHello();

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

I stored this .java file in C:\fiji-win32-20110307\Fiji.app\plugins
folder and and then placed the Hello_World.dll file in the path: "C:
\fiji-win32-20110307\Fiji.app" I am getting the error:

Started Hello_World.java at Wed May 30 09:17:56 CDT 2012
C:\fiji-win32-20110307\Fiji.app\plugins\Hello_World.java:12: cannot
find symbol
symbol : method loadlibrary(java.lang.String)
location: class fiji.JNI
JNI.loadlibrary("Hello_World");
^
1 error
..


Alternatively I tried compiling the java file in Eclipse first but I
couldn't proceed as I couldn't import "import fiji.JNI;".. How can I
import this?

Can anyone please give some pointers on where to place the dll file,
abt setting the path and any other required steps?

Thanks,
Lakshmi
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Johannes Schindelin
2012-05-31 22:54:18 UTC
Permalink
Hi,
Post by lakshmi
I am trying to write plugins for fiji which uses native code. I am new
to this field and so I know very less about this.
In Fiji I went to the path File>New>Script and wrote the
import fiji.JNI;
import ij.IJ;
import ij.plugin.*;
public class Hello_World implements PlugIn {
static
{
JNI.loadlibrary("Hello_World");
}
native void sayHello();
public void run(String arg)
{
sayHello();
}
}
I stored this .java file in C:\fiji-win32-20110307\Fiji.app\plugins
Started Hello_World.java at Wed May 30 09:17:56 CDT 2012
C:\fiji-win32-20110307\Fiji.app\plugins\Hello_World.java:12: cannot
find symbol
symbol : method loadlibrary(java.lang.String)
location: class fiji.JNI
JNI.loadlibrary("Hello_World");
^
1 error
..
Alternatively I tried compiling the java file in Eclipse first but I
couldn't proceed as I couldn't import "import fiji.JNI;".. How can I
import this?
Can anyone please give some pointers on where to place the dll file,
abt setting the path and any other required steps?
See https://list.nih.gov/cgi-bin/wa.exe?A2=IMAGEJ;335b0cdb.1205

In particular, you were probably also bitten by the following two issues:

1) you need to compile with -D_JNI_IMPLEMENTATION=1
2) you need to link with -kill-at

Ciao,
Johannes
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Grant
2012-06-01 02:46:58 UTC
Permalink
Lakshmi,

JNI.loadlibrary("Hello_World"); should be
System.loadlibrary("Hello_World");

- Grant
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Curtis Rueden
2012-06-01 16:16:15 UTC
Permalink
Hi Grant,
Post by Grant
JNI.loadlibrary("Hello_World"); should be
System.loadlibrary("Hello_World");
Actually, Fiji has a JNI class that makes loading libraries easier; see:
http://fiji.sc/javadoc/fiji/JNI.html
http://fiji.sc/JNI.java

Lakshmi's error is because of capitalization ("loadlibrary" vs.
"loadLibrary").

As Johannes mentioned, more details are at:
http://fiji.sc/JNI

Regards,
Curtis
Post by Grant
Lakshmi,
JNI.loadlibrary("Hello_World"); should be
System.loadlibrary("Hello_World");
- Grant
--
Please avoid top-posting, and please make sure to reply-to-all!
Mailing list web interface: http://groups.google.com/group/fiji-users
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Grant
2012-06-01 16:44:32 UTC
Permalink
Curtis --
Thanks, I didn't know about that rather useful thing.
-- Grant
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Johannes Schindelin
2012-06-01 16:58:19 UTC
Permalink
Hi Grant,
Post by Grant
JNI.loadlibrary("Hello_World"); should be
System.loadlibrary("Hello_World");
JNI is imported from fiji-lib.jar and specifically designed to cope with
the fact that we do not want to fiddle with the system-wide library search
path (and dealing with the platform-specific issues; you have the luxury
of needing to deal only with Linux, I don't...).

Ciao,
Dscho
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
lakshmi narjala
2012-06-06 13:30:07 UTC
Permalink
Hi,

I am writing a python program which runs an .exe file everytime it is
executed.
ex:- I have a.exe which was generated after compile a C program which
creates a txt file, writes a sentence into it and closes the file.
I initially wrote a pure python program which invokes the a.exe file and
writes the text into it. I tried to implement this in Fiji and wrote the
program is:-

import os

cmd="C:/Users/user1/Desktop/a.exe"
i=5

while i:

os.popen(cmd)
IJ.showMessage("While Block")
i-=1

For this I have used: os.popen() function command.. But when I use it in
Fiji it does not work. Can you please advice on the same.

Thanks,
Lakshmi
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Curtis Rueden
2012-06-06 16:00:23 UTC
Permalink
Hi Lakshmi,
Post by lakshmi narjala
For this I have used: os.popen() function command.. But when I use it in
Fiji it does not work.
My first guess was that it could be due to Jython versus Python. Fiji uses
Jython, which is an implementation of the Python language on top of the
JVM. It differs from the C version of Python in several ways. My thought
was that perhaps the os.popen command was not supported in Jython.

However, I just did a quick test, and for me it does work.

First test (*nix only):
import os
os.popen("pwd")

But nothing appeared in the Script Editor log, so I tried:
import os
os.popen("pwd > /Users/curtis/pwd.txt")

And after running the script, the file was there. So popen is working as
expected.

Your problem could be a Windows-specific issue, or something else. It is
not really feasible to comment further without seeing the error message you
are receiving. So if you require further assistance, please provide more
details.

HTH,
Curtis

P.S. I also found this page on the Jython site documenting one alternative
to using os.popen. Perhaps it would work for you:
http://www.jython.org/docs/library/subprocess.html


On Wed, Jun 6, 2012 at 8:30 AM, lakshmi narjala
Post by lakshmi narjala
Hi,
I am writing a python program which runs an .exe file everytime it is
executed.
ex:- I have a.exe which was generated after compile a C program which
creates a txt file, writes a sentence into it and closes the file.
I initially wrote a pure python program which invokes the a.exe file and
writes the text into it. I tried to implement this in Fiji and wrote the
program is:-
import os
cmd="C:/Users/user1/Desktop/a.exe"
i=5
os.popen(cmd)
IJ.showMessage("While Block")
i-=1
For this I have used: os.popen() function command.. But when I use it in
Fiji it does not work. Can you please advice on the same.
Thanks,
Lakshmi
--
Please avoid top-posting, and please make sure to reply-to-all!
Mailing list web interface: http://groups.google.com/group/fiji-users
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Johannes Schindelin
2012-06-06 17:40:30 UTC
Permalink
Hi Lakshmi,
Post by lakshmi narjala
cmd="C:/Users/user1/Desktop/a.exe"
os.popen(cmd)
On Windows, the paths must use backslashes for the execution to succeed.
Note that you need to escape the backslashes because they are the escape
character in Strings (which makes the choice of backslashes for DOS paths
a poor one):

cmd = "c:\\Users\\user1\\Desktop\\a.exe"

Ciao,
Johannes
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Loading...