on 07-12-2021 6:15 AM
Hello Experts,
I am currently working on Amazon SP-API integration and developed a Java class to handle the AWS4 signature.
I am trying consume this java class as an external jar in a groovy script and call it's methods.
There is an option to upload the Jar files in the Iflow resources, but when I am referring the custom java class package in the local groovy script it is giving error.
I am wondering how in CF env. / WebUI, I can refer the external Jars inside my Groovy scripts.
Request your help and advice.
Thanks
Sugata
Hi Sugata
What you are doing is correct. You didn't mention which specific error you are getting, but I have two guesses:
As for that old blog post of mine, please read the first paragraph again 😄
Regards,
Morten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Morten,
Thank you for your reply! Yes, I have followed the same-
1. compiled the java class using jdk 8
2. referred to the full path of the package name in the groovy script
3. uploaded the external jar in the local reference of Iflow.
Here is the script -
import com.sap.gateway.ip.core.customdev.util.Message;
import com.sap.javagroovy; // external Java class package
import java.util.HashMap;
import src.main.resources.lib.*; // thought of adding this as jars are uploaded into this
def Message processData(Message message) {
//Body
JavaGroovy jg = new JavaGroovy();
def ret = jg.addinGroovy(3,12);
message.setBody(ret);
return message;
}
Here is the error log -
Error Details
Error Details
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script1__Script.groovy: 19: unable to resolve class com.sap.javagroovy
@ line 19, column 1.
import com.sap.javagroovy;
^
script1__Script.groovy: 24: unable to resolve class JavaGroovy
@ line 24, column 19.
JavaGroovy jg = new JavaGroovy();
^
script1__Script.groovy: 24: unable to resolve class JavaGroovy
@ line 24, column 24.
JavaGroovy jg = new JavaGroovy();
^
3 errors
, cause: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script1__Script.groovy: 19: unable to resolve class com.sap.javagroovy
@ line 19, column 1.
import com.sap.javagroovy;
^
script1__Script.groovy: 24: unable to resolve class JavaGroovy
@ line 24, column 19.
JavaGroovy jg = new JavaGroovy();
^
script1__Script.groovy: 24: unable to resolve class JavaGroovy
...
Thanks
Sugata
Hi sugata.bagchi2
The error message is fairly clear: There is no class called com.sap.javagroovy. If the class is actually called JavaGroovy, specify that. If javagroovy is a package, and you want to import all classes in that package, use: import com.sap.javagroovy.*
Also, put your classes in a package of your own rather than com.sap.
Regards,
Morten
Thank you Morten.
My Bad! not sure how have I missed the *.
I have updated the code, but still getting the error-
Here is my external Java class -
and below is my updated GroovyScript-
import com.sap.gateway.ip.core.customdev.util.Message;
import com.sap.javagroovy.*;
import java.util.HashMap;
//import src.main.resources.lib.*;
def Message processData(Message message) {
//Body
JavaGroovy jg = new JavaGroovy();
def ret = jg.addinGroovy(3,12);
message.setBody(ret);
return message;
}
But still getting the below error -
Error Details
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script1__Script.groovy: 24: unable to resolve class JavaGroovy
@ line 24, column 19.
JavaGroovy jg = new JavaGroovy();
^
script1__Script.groovy: 24: unable to resolve class JavaGroovy
@ line 24, column 24.
JavaGroovy jg = new JavaGroovy();
^
2 errors
, cause: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script1__Script.groovy: 24: unable to resolve class JavaGroovy
@ line 24, column 19.
JavaGroovy jg = new JavaGroovy();
^
script1__Script.groovy: 24: unable to resolve class JavaGroovy
@ line 24, column 24.
JavaGroovy jg = new JavaGroovy();
^
Hi sugata.bagchi2
Are you sure you've packaged the JAR correctly? It should contain a directory called com, with a subdirectory called sap, with another subdirectory called javagroovy, which then contains the JavaGroovy.class compiled class.
So:
com\
sap\
javagroovy\
JavaGroovy.class
If the JAR is correctly packaged, please try renaming your package to, say, sugata.javagroovy or something similar. I.e. not com.sap. You should do that anyway, since your code doesn't belong in a subpackage of com.sap.
Regards,
Morten
Hello Morten!
You are the best!
After changing the package name to a custom one, it worked. But this is something unusual.
Thank you so much for your help.
Thanks
Sugata
Hello Sugata,
Please see if this helps you.
and
Regards,
Karuna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Karunaharan,
I went through the links from Help SAP you provided.
But, they are not addressing my requirements.
please have look into this blog, which says about this using eclipse tool not the webui or cf.
https://blogs.sap.com/2017/01/23/how-to-use-external-java-libraries-in-hci/
My requirement is to do the same using CF env.
Thanks
Sugata
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.