cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to call Java-function from Powerbuilder

Former Member
0 Kudos

Hello, i am using Powerbuilder 12.1 build 6639 on Windows 7 Pro 64 bit. //constant string CLASSPATH = "C:\Eigene Dateien\pb105\kmt" string classpath = ".;C:\Eigene Dateien\pb105\kmt" //string classpath = "C:\Program Files (x86)\Java\jre1.8.0_66\bin\client" //string classpath = "" boolean lb_err long ll_rc string ls_msg, ls_cp, ls_version JavaVM ln_java_vm EJBConnection ln_ejb_conn Simple ln_hw do ln_java_vm = create JavaVM ll_rc = ln_java_vm.createjavavm( CLASSPATH, true) if ll_rc < 0 then Messagebox(gs_app_tit, "createjavavm: " + string(ll_rc)) lb_err = true exit end if ls_cp = ln_java_vm.getjavaclasspath() ls_version = ln_java_vm.getjavaVMversion() Messagebox(gs_app_tit, "java version: " + string(ls_version) + " class_path: " + ls_cp) // createjavainstance via JavaVM Class // ll_rc = ln_java_vm.Createjavainstance(ln_hw, "Simple") //-> PB crashes here // createjavainstance via EJBConnection Class (deprecated!) ln_ejb_conn = create EJBConnection ll_rc = ln_ejb_conn.createjavainstance(ln_hw, "simple") // return value is -1 (failed to create java class) Messagebox(gs_app_tit, "createjavainstance:" + string(ll_rc)) try Messagebox("", "before sayHello") ls_msg = ln_hw.sayHello() Messagebox("", "3") catch (CreateException ce) Messagebox(gs_app_tit, "Create Exception: " + ce.getMessage()) catch (Throwable t) Messagebox(gs_app_tit, "Other Exception: " + t.getMessage()) end try Messagebox("", ls_msg) loop while 1 = 0 destroy ln_java_vm return 1

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Martin;

   My STD Integrated Foundation Class framework supports the JNI used by PB Classic to call your Java classes from a PB application. I have a detailed example and explanation of its workings that you can try out - plus, look at the way I coded it (click here). 

HTH

Regards ... Chris

Former Member
0 Kudos

Hi Chris, you saved my day! I downloaded your sample, executed it on my Computer and the Java call worked perfectly. After reviewing your code I realized that your does the same as mine. So I tried to copy your HelloWorld - Classes to my Directory and  was happy that I could call it with my PB app. And now it is clear to me what the error was: On my System I have an intelliJ Installation for my Java Projects and it uses as Default a 64 bit JDK Version 1.8.0_45. It seems to be clear that classes compiled with this Version can't be executed with the PB shipped JRE 32 bit Version 1.6.0_02. The only Thing I wonder is, is it the higher Version of the classes (I think so) or the 64 bit structure that causes the Problem? Thank you Chris and Merry Christmas to everyone!

Former Member
0 Kudos

Hi Martin;

   Yes, I was using Java 1.7.0_55 to compile & test my frameworks support of the PB to Java feature set. Once I upgraded to JVM 1.8.0_66 the example application crashes as you first reported after recompiling the Java Classes. However, restoring the 1.7.0_55 class compiles runs fine with the 1.8.0_66 JVM.

  I'll have to dig deeper into this.

Regards ... Chris

PS: Happy New Year!

Former Member
0 Kudos

Hello, For my purposes I now use the same JDK/JRE (PB shipped 1.6.0_02 for compiling AND executing the classes. This is the savest way and I have no Troubles. Some further reading on this Topic concluded me that same Major Versions should be compatible, and higher execution Versions are backward compatible with lower compile Versions. That's the theory, practically I use my solution. Regards and Happy New Year!

Former Member
0 Kudos

Hi Martin;

   I agree ... Sticking with the Java SDK version that ships with your PB IDE is the safest way to go for now.

BTW: if this has answered your original question - please mark your question as answered.

Happy 2016!

Regards ... Chris

Answers (0)