I have a java class that has one method that takes some parameters as input and returns an array. I need to call this java method from PowerBuilder desktop application by passing the required parameters, and then capture the response from the method (array in this case.) How can this be achieved? Please provide step-by-step information for the same. Thanks!
- You are here:
- Home
- Q&A
- Q&A
- PowerBuilder
- Calling a java class from PowerBuilder 2017 R3
- Suhas Shravagi
- PowerBuilder
- Thursday, 3 September 2020 18:42 PM UTC
- Thursday, 3 September 2020 19:32 PM UTC
- PowerBuilder
- # Permalink
Hi Suhas,
Chris has excellent "direct" approach for current releases of PB. Thanks, Chris!
Olan has excellent example of interfacing via command-line which also works for older versions of PB.
An alternative is to wrap your java class in COM - and then call via OLEObject like any other COM. This example calls java code from VBScript using COM as interface.
HTH /Michael
- Thursday, 3 September 2020 20:19 PM UTC
- PowerBuilder
- # 1
This is not all that difficult if the class you are calling is set up to handle all of the parameter the Java code will require. The base of the following code is the call to the RUN command.
// OKnight, 29-JAN-2007.
ib_first_pass = TRUE
ls_java_exe = "c:\windows\system32\java.exe" // We have code to ensure this is correct
is_java_title = ls_java_exe
logWrite (il_aurlog, " Source UID = " + string (ii_source_uid))
logWrite (il_aurlog, " File name = " + is_pathname + is_filename)
// OKnight, 15-FEB-2005. Wrap all string parms in double-quotes.
// The variables used in the string below were all determined previously.
// The class is StartCabsProcessing and everything after that are the class parameters.
// ----------------------------------------------------------------------------------------------------------
ls_cmd = ls_java_exe + &
' -Xmx' + String(ii_memory) + 'm' + &
' -cp "' + ls_jar_file + '"' + &
' StartCabsProcessing -UID=' + String(ii_aur_source_uid) + &
' -FILEUID=' + String(ii_source_uid) + &
' -SS=' + String(il_batch_size) + &
' -CONFIGFILE="' + ls_config_file + '"' + &
' "' + is_pathname + is_filename + '"'
// Actually start the JAVA process....
li_ret = run (ls_cmd, Minimized!)
IF li_ret <= 0 THEN
ls_txt = "The RUN command failed to start JAVA.EXE. ~r~n " + &
"~r~n Java: " + ls_java_exe + &
"~r~n CFG: " + ls_config_file + &
"~r~n Jar: " + ls_jar_file + &
"~r~n Path: " + is_pathname + &
"~r~n File: " + is_filename + &
"~r~n Memory: " + String(ii_memory) + &
"~r~n UID: " + String(ii_aur_source_uid) + &
"~r~n Source ID: " + String(ii_source_uid) + &
"~r~n Batch Size: " + String(il_batch_size) + &
"~r~n~r~n ls_cmd: " + ls_cmd
GOTO Exit_Function
END IF
// Prevent the user from closing the window before we are done
of_set_prevent_close (TRUE)
// OKnight, 10-NOV-2014, R#550105: Enable the CANCEL button.
cb_cancel_processing.Enabled = TRUE
cb_folder_start.Enabled = FALSE
wf_set_progress (0.20) // Progress meter displayed to the user
ib_javaprocstarted = TRUE
ls_pathname = is_pathname + is_filename + ".out" // OKnight, 24-OCT-2006.
// OKnight, 24-OCT-2006. Its possible that the Java processing will complete
// before we get here, so check for that condition.
time lt_start, lt_curr
long ll_seconds
Sleep (2)
lt_start = Now ()
DO
val = FindWindowW(0, is_java_title)
lb_exists = FileExists (ls_pathname)
lt_curr = Now ()
ll_seconds = SecondsAfter (lt_start, lt_curr)
Sleep (0.5)
LOOP UNTIL(val > 0) OR (val = 0 AND lb_exists) OR (ABS (ll_seconds) > 5)
// OKnight, 14-FEB-2007.
logWrite (il_aurlog, "wf_start_java - val = " + string (val))
- Thursday, 3 September 2020 20:25 PM UTC
- PowerBuilder
- # 2
Hi Suhas;
FYI: You can call a Java Class and its method(s) directly from a PB App.
Example: http://chrispollach.blogspot.com/2019/09/pb2j.html
HTH Regards ... Chris
- Chris Pollach @Appeon
- Thursday, 3 September 2020 23:11 PM UTC
I have PB 12.x examples in my Archive folder. I have older ones if needed in my backups (if needed).
https://sourceforge.net/projects/stdfndclass/files/Applications/PowerBuilder/PB2Java/Archive
-
Helpful Loading... Helpful 0
- Suhas Shravagi
- Friday, 4 September 2020 19:18 PM UTC
1) Created a java class as below:
public class Converter implements ConverterHome {
public double dollarToYen(double dollar) {
return dollar * 60;
}
}
2) Created an interface as below:
public interface ConverterHome {
public double dollarToYen(double dollar);
}
3) compiled and copied both these .class files in the same directory as my application exe.
4) Thru PowerBuilder, set the required parameters in the EJBClient Proxy Wizard as below:
EJB Component name: Converter
EJB Component Home Interface name: ConverterHome
EJB stub classpath: left blank
Prefix for EJB Component Proxy name: left blank
5) Selected the deployment pbl and then start deploying the proxy. Here it is throwing the error as:
---------- Deploy: Deploy of p_mailsend_ejbclientproxy (12:45:15 AM)
Retrieving PowerBuilder Proxies from EJB...
Generation Errors: Can't get information of ConverterHome
Deployment Error: No files returned for package/component 'Converter'. Error code: Unknown. Proxy was not created.
---------- Finished Deploy of p_mailsend_ejbclientproxy (12:45:15 AM)
Can you help what is wrong in the procedure above? I have added the pbejbclient170.pbd in in the library search path.
-
Helpful Loading... Helpful 0
- Chris Pollach @Appeon
- Tuesday, 8 September 2020 17:43 PM UTC
Just follow my PB2017 Rx example and documentation from the above links. If that does not help, I would suggest posting your test app work here for us to look into further.
Regards ... Chris
-
Helpful Loading... Helpful 0
- Page :
- 1
However, you are not allowed to reply to this question.