Consider the following simple class :
[Simple.java]
public class Simple {
public Simple() { }
public static String sayHello(){
return "Hello world";
}
public String sayNonStaticHello(){
return "Hello world";
}
public static void main(String[] args) {
System.out.println(Simple.sayHello());
}
}[SimpleHome.java]
public interface SimpleHome { }
JavaVM lJavaVM
EJBConnection lEJBConn
Simple lnv_simple
long ll_return
lJavaVM = CREATE JavaVM
// need to specify the classpath form the Simple class
ll_return = &
lJavaVM.CreateJavaVM("C:\Applications\rega\dev\Work\pb9\Target3", FALSE)
CHOOSE CASE ll_return
CASE 1
CASE 0
CASE -1
MessageBox ( "", "jvm.dll was not found in the classpath.")
CASE -2
MessageBox ( "", "pbejbclient90.jar file was not found." )
CASE ELSE
MessageBox ( "", "Unknown result (" + String (ll_return ) + ")" )
END CHOOSE
IF ll_return < 0 THEN
DESTROY lJavaVM
END IF
lEJBConn = CREATE EJBConnection
ll_return = lEJBConn.CreateJavaInstance( lnv_simple, "Simple")
IF ll_return <> 0 THEN
MessageBox("", "CreateJavaInstance returned " +string(ll_return))
destroy lEJBConn
ELSE
TRY
MessageBox("From Java!" , lnv_simple.sayNonStaticHello())
CATCH (CreateException ce)
MessageBox( "Create Exception", ce.getMessage() )
CATCH (Throwable t)
MessageBox(" Other Exception", t.getMessage())
END TRY
END IF
You can download this example here
Written and compiled by Réal Gagnon ©1998-2005
[ home ]