CNI Invocation of Java code from C++ example fails
Andrew Haley
aph@redhat.com
Tue Jan 28 14:51:00 GMT 2003
Works fine for me. It's not nice, but I can't think of a fix right now.
// test.cc
#include <gcj/cni.h>
#include <java/lang/System.h>
#include <java/io/PrintStream.h>
#include <java/lang/Throwable.h>
extern void _Jv_ThisExecutable(char const*);
int main(int argc, char **argv)
{
using namespace java::lang;
_Jv_ThisExecutable (argv[0]);
try
{
JvCreateJavaVM(NULL);
JvAttachCurrentThread(NULL, NULL);
String *message = JvNewStringLatin1("Hello from C++");
JvInitClass(&System::class$);
System::out->println(message);
JvDetachCurrentThread();
}
catch (Throwable *t)
{
System::err->println(JvNewStringLatin1("Unhandled Java exception:"));
t->printStackTrace();
}
}
More information about the Gcc-bugs
mailing list