Hunter,
This is not Jess specific question. JVM simply can not find Java class
to load.
Can you show snippet of the C++ code that starts jvm and tries to load
TestJNIJessinvoke?
As for overall design, is C++ requirement? Can you do it all in Java?
Dusan Sormaz
On 9/26/2011 8:51 PM, Hunter McMillen wrote:
Hello everyone,
I am working on a project where I am using a C++ framework and API to
create a game agent. My agent has to be flexible so it can react
to/predict events that occur inside the game environment, Jess has the
kind of flexibility that I need for my agent to be good, but I am
having trouble connecting to Jess from C++ and that is where I was
hoping someone could help me out.
*What I am doing right now*
I have a C++ program that starts a Java Virtual Machine and searches
for a Java class file name "TestJNIJessInvoke"
Inside of "TestJNIJessInvoke.java" I define a simple function in Jess,
and try to call that function then print the result
import jess.*;
public class TestJNIJessInvoke
{
public static void main(String[] args) throws JessException
{
Rete r = new Rete();
r.executeCommand("(deffunction square (?n) (return (* ?n ?n)))");
Value v = r.executeCommand("(square 3)");
System.out.println(v.intValue(r.getGlobalContext()));
}
}
But when I try to compile and link the C++ file with:
*cl *
* -I"C:\Program Files\Java\jdk1.7.0\include" *
* -I"C:\Program Files\Java\jdk1.7.0\include\win32" *
* TestJNIJessInvoke.cpp *
* -link "C:\Program Files\Java\jdk1.7.0\lib\jvm.lib"*
*
*
I get a class loader exception:
*Exception in thread "main" java.lang.NoClassDefFoundError: jess/Rete*
* at TestJNIJessInvoke.main(TestJNIJessInvoke.java:6)*
*Caused by: java.lang.ClassNotFoundException: jess.Rete*
* at java.net.URLClassLoader$1.run(URLClassLoader.java:366)*
* at java.net.URLClassLoader$1.run(URLClassLoader.java:355)*
* at java.security.AccessController.doPrivileged(Native Method)*
* at java.net.URLClassLoader.findClass(URLClassLoader.java:354)*
* at java.lang.ClassLoader.loadClass(ClassLoader.java:423)*
* at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)*
* at java.lang.ClassLoader.loadClass(ClassLoader.java:356)*
* ... 1 more*
*
*
Exception in thread "main" java.lang.NoClassDefFoundError: jess/Rete
at TestJNIJessInvoke.main(TestJNIJessInvoke.java:6)
Caused by: java.lang.ClassNotFoundException: jess.Rete
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more
*Questions*
1) Is there some other directory that I am supposed to be including
that has the .class files for Jess? Right now all I am including is
jess.jar
2) Is the general design I have a good idea? or is there a better way
to facilitate communication between Jess and C++?
Thanks,
Hunter McMillen
--
***************************************************
* Dusan Sormaz, PhD, Associate Professor
* Ohio University
* Department of Industrial and Systems Engineering
* 284 Stocker Center, Athens, OH 45701-2979
* phone: (740) 593-1545
* fax: (740) 593-0778
* e-mail: sor...@ohio.edu
* url: http://oak.cats.ohiou.edu/~sormaz/
***************************************************