App Connect

 View Only
Expand all | Collapse all

How to import external Java library/classes

  • 1.  How to import external Java library/classes

    Posted Mon March 13, 2023 09:29 AM

    Hello, I'm currently trying to call an endpoint using JavaComputeNode. Unfortunately, there is no current library in IBM ACE that I can use (I suppose). 
    I'm asking if: is it possible to import an external java library/packages/classes/jar file so that I can call an endpoint using JavaComputeNode?

    Thanks in advance for those who will respond in my question



    ------------------------------
    Nathaniel Santiago
    ------------------------------


  • 2.  RE: How to import external Java library/classes

    IBM Champion
    Posted Tue March 14, 2023 02:30 AM
    Edited by Matthias Blomme Tue March 14, 2023 02:30 AM

    Hi Nathaniel

    Sure you can, in a number of ways.

    You can add java libraries inside an application, you can add them to the shared classes of your integration server, you can add them to the shared classes the node or you can create a custom node and add them by installing that one in the runtime.

    Have a look at the following documentation to see how it works

    https://www.ibm.com/docs/en/app-connect/12.0?topic=overview-java-shared-classloader

    Can I ask why you can't call the endpoint with any other means, like rest node or something?

    ------------------------------
    Regards
    Matthias Blomme
    ------------------------------



  • 3.  RE: How to import external Java library/classes

    Posted Tue March 14, 2023 02:44 AM
    Edited by Nathaniel Santiago Tue March 14, 2023 02:46 AM

    Hi @Matthias Blomme, thank you for noticing my question.

    I have successfully imported a jar file into my project. I have also used the classes/methods inside the JavaComputeNode without any errors. 
    (I followed the instructions here: https://www.ibm.com/docs/en/app-connect/11.0.0?topic=java-adding-code-dependencies)

    Unfortunately, When I deployed it in my TEST_SERVER and execute it, it shows 

    java.lang.NoClassDefFoundError

    I think I missed the highlighted instructions below, would you clarify this for me? I'm having a hard time finding the correct shared-classes directory




    ------------------------------
    Nathaniel Santiago
    ------------------------------



  • 4.  RE: How to import external Java library/classes

    IBM Champion
    Posted Tue March 14, 2023 02:56 AM
    Edited by Matthias Blomme Tue March 14, 2023 02:56 AM

    @Nathaniel Santiago 

    What environment are you running on? I'm going to assume windows.

    According to the IBM docs (I have not tried this for an standalone integration server) the shared-classes directory is located directly beneeth the runtime of your SIS.

    So for my system with a SIS called TEST_SERVER that would give

    C:\Users\blmm_m\IBM\ACET12\workspace\TEST_SERVER\shared-classes

    You will need to create this folder first.



    ------------------------------
    Regards
    Matthias Blomme
    ------------------------------



  • 5.  RE: How to import external Java library/classes

    Posted Tue March 14, 2023 04:02 AM
    Edited by Nathaniel Santiago Tue March 14, 2023 04:03 AM

    I tried your suggestion, but sadly it didn't work, here is my directory

    I also tried to put the files here (this is the main IBM installation folder I think), but still nothing
    Here's the error



    ------------------------------
    Nathaniel Santiago
    ------------------------------



  • 6.  RE: How to import external Java library/classes

    Posted Tue March 14, 2023 10:02 PM
    Edited by Nathaniel Santiago Wed March 15, 2023 01:14 AM

    @Matthias Blomme Hello again. are there other ways to import java libraries other than jar files? Using jar file still doesn't work for me. 

    I need to import an HTTP Request Library and a JSON Library for the feature that we need to implement. (Call and APIEndpoint using HTTP Request Library and Modify the request/response using the JSON Library in a JavaComputeNode)
    Thanks in advance



    ------------------------------
    Nathaniel Santiago
    ------------------------------



  • 7.  RE: How to import external Java library/classes

    IBM Champion
    Posted Wed March 15, 2023 02:19 AM

    Hi Nathaniel

    HTTP Request/Reply with json is perfectly doable from within esql, so not sure what makes your request so special that you need special java classes for that.

    You are showing 2 separate print screens, first is from a stand alone IS and the second is from a node managed is. 

    For node managed IS, you actually have 3 shared classes directories

    • system wide: C:\ProgramData\IBM\MQSI\shared-classes
    • node wide: C:\ProgramData\IBM\MQSI\components\ACENODE\shared-classes
    • integration server wide: C:\ProgramData\IBM\MQSI\components\ACENODE\servers\IS1\shared-classes

    If you put shared-classes anywhere here, they are picked up by any flow inside the integration server. Aside from this you can include the jar files inside the bar you deploy.

    In the below screenshot I simply referenced the jar file from the java project and it gets pulled inside the bar file.

    You can also decompile java code you need and add it as java files to your java project, but I wouldn't advice that.

    Did you try to do a restart of the IS/NODE after putting the jars in the shared-classes directory?



    ------------------------------
    Regards
    Matthias Blomme
    ------------------------------



  • 8.  RE: How to import external Java library/classes

    Posted Wed March 15, 2023 03:56 AM
    Edited by Nathaniel Santiago Wed March 15, 2023 03:56 AM

    We want to avoid using drag-and-drop nodes like HTTP Request/Reply because we will send multiple asynchronous calls "dynamically". It is impossible with nodes like that. That's why we want our JavaComputeNode to do all the logic

    I also tried again to put the jar files in the 3 shared classes directories you mentioned. still doesn't work :(

    and yes also tried restarting IS even the whole ACE toolkit.

    here's a screenshot. 




    ------------------------------
    Nathaniel Santiago
    ------------------------------



  • 9.  RE: How to import external Java library/classes

    IBM Champion
    Posted Wed March 15, 2023 04:39 AM

    I can't really debug this without having access to your system but if the proper jars are added in the proper shared-classes directory (one of the matching directories will suffice), then ACE will pick this up automatically. This is the basics of the classloader.

    Do you see any errors in your console log of the IS/NODE?

    Copy past the jars you need inside your java project. I beleive only local jars will be pulled inside the bar file, jars added as Exeternal jars are not.



    ------------------------------
    Regards
    Matthias Blomme
    ------------------------------



  • 10.  RE: How to import external Java library/classes

    IBM Champion
    Posted Wed March 15, 2023 08:22 AM

    Have you looked at the dynamic runtime override properties of the HTTP Request node? There is no need for your java compute node, just some elaborate logic in the nodes preceding your HTTP Request node should do it!



    ------------------------------
    Francois Brandelik
    ------------------------------



  • 11.  RE: How to import external Java library/classes

    Posted Thu March 16, 2023 03:41 AM

    I totally agree with this. It seems you are causing yourself a lot of problems for something the platform can do easier for you...



    ------------------------------
    Lars Dehli
    ------------------------------