Hello,
I've tried to start neuron from a java class by doing the following
public class test
{
public static void main(String args[])
{
Neuron.execute(new String("print \"Hello, World\""));
}
}
but after successful compile, I get a runtime error :
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
Exception in thread "main" java.lang.UnsatisfiedLinkError: execute
at neuron.Neuron.execute(Native Method)
at test.main(test.java:9)
I've compiled neuron with --with-nrnjava so I dont know what
vent wrong ..
also I could not find "NEURON + Java Interface programmer
reference" anywhere, it is originally linked in
nrn/src/nrnjava/nrnjava.html. If someone knows a good
information source dealing with neuron java coding or
examples I would be glad if he could point it out
(my goal is to start neuron from java and let it load and
execute a hoc file)
thanks in advance
peter
run neuron from a java class
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Location of nrnjava.html and javanrn.html
After I extracted the gzipped tar file to /usr/local/src/nrn-5.7,
nrnjava.html and javanrn.html are in /usr/local/src/nrn-5.7/src/nrnjava
nrnjava.html and javanrn.html are in /usr/local/src/nrn-5.7/src/nrnjava
well, with location of nrnjava.html and javanrn.html I didn't have a
problem, but I couldn't locate "NEURON + Java Interface programmer
reference" refernced with :
http://www.neuron.yale.edu/neuron/insta ... index.html
from :
http://www.neuron.yale.edu/neuron/insta ... njava.html
.
In the same way I couldn't find the " early development notes" at:
http://www.neuron.yale.edu/neuron/insta ... notes.html
I've studied nrnjava.html and tried to rebuild examples with no success,
so I hope for some subsidiary information in addition to nrnjava, helping
me on.
The error
>Exception in thread "main" java.lang.UnsatisfiedLinkError: execute
>at neuron.Neuron.execute(Native Method)
makes me suppose that there had to be loaded a Neuron speciffic dll
in manner :
System.load("neuron.so");
where JNI Api is build in. neuron.tar is in my classpath but I'm not sure
if dll linking is done here. however,the java statement
import neuron.Neuron;
is accepted by javac.
As an alternative I 've tried to run Neuron out of java by doing a System
call :
System.execute("nrngui",null,null) with connecting sdtin and stdout of
this java process with java streams an feeding them with neuron
commands. Unfortunately this didn't work either (also it's running and
nrngui is starting up, it accepts no streaminput and gives no output.
nrngui seems to need a true shell environment in order to work properly
or there is some problem with sh environment used by java subprocess calls)
If someone more experienced could give me a hint or has a suggestion
I would be very glad
thanks
peter
problem, but I couldn't locate "NEURON + Java Interface programmer
reference" refernced with :
http://www.neuron.yale.edu/neuron/insta ... index.html
from :
http://www.neuron.yale.edu/neuron/insta ... njava.html
.
In the same way I couldn't find the " early development notes" at:
http://www.neuron.yale.edu/neuron/insta ... notes.html
I've studied nrnjava.html and tried to rebuild examples with no success,
so I hope for some subsidiary information in addition to nrnjava, helping
me on.
The error
>Exception in thread "main" java.lang.UnsatisfiedLinkError: execute
>at neuron.Neuron.execute(Native Method)
makes me suppose that there had to be loaded a Neuron speciffic dll
in manner :
System.load("neuron.so");
where JNI Api is build in. neuron.tar is in my classpath but I'm not sure
if dll linking is done here. however,the java statement
import neuron.Neuron;
is accepted by javac.
As an alternative I 've tried to run Neuron out of java by doing a System
call :
System.execute("nrngui",null,null) with connecting sdtin and stdout of
this java process with java streams an feeding them with neuron
commands. Unfortunately this didn't work either (also it's running and
nrngui is starting up, it accepts no streaminput and gives no output.
nrngui seems to need a true shell environment in order to work properly
or there is some problem with sh environment used by java subprocess calls)
If someone more experienced could give me a hint or has a suggestion
I would be very glad
thanks
peter
When one builds NEURON with the --with-nrnjava configure option, it means that immediately after NEURON is launched, it will load a JVM java virtual machine. In this case, instead of calling a main program in java which then loads NEURON, call a java control routine from NEURON. Consider the file, test.java
compiled with
Then the hoc program, test1.hoc
calls the java static method from which you can do anything you wish. Note that my working directory was added to the classpath so that I could load the Test class.
Code: Select all
import neuron.*;
public class test
{
public static void test1() {
Neuron.execute(new String("print \"Hello, World\""));
}
}
Code: Select all
javac -classpath .:$N/share/nrn/classes/neuron.jar test.java
Code: Select all
load_java("neuron.NrnClassLoader", "NCL")
objref ncl
ncl = new NCL()
ncl.add("file:/home/hines/neuron/nrntest/java/")
load_java("test", "Test")
objref test
test = new Test()
test.test1()
But if NEURON is NOT built with the --with-nrnjava configure option it can still be controlled by java via stdin/stdout. Just have
Java launch NEURON with the -isatty argument
and everytime java sees the oc> prompt
NEURON is ready for another command.
I have an example that uses a pair of files
called POpen.java and popen.hoc where
the latter uses the statements
but to avoid clutter here, send me an email
and I'll send a zip file.
Java launch NEURON with the -isatty argument
and everytime java sees the oc> prompt
NEURON is ready for another command.
I have an example that uses a pair of files
called POpen.java and popen.hoc where
the latter uses the statements
Code: Select all
// the -isatty arg flushes every line but also produces an oc> prompt
// with no newline when the interpreter is ready to accept input
sprint(tstr, "/home/hines/neuron/nrnobj/i686/bin/nrniv -isatty")
po = new POpen(tstr)
and I'll send a zip file.