IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
Expand all | Collapse all

Call a static global function

  • 1.  Call a static global function

    Posted 12/15/15 12:32 PM

    Hi,

    I’ve created a class with a static méthod : helloWorld()

    How to call helloWorld from all my others class and packages ?
    My import clause fails to compile… and the call of my function too…

    Out of webMethods I do not meet the problem…

    Regards


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 2.  RE: Call a static global function

    Posted 12/15/15 12:42 PM

    Hi Cedric,

    all Packages which need access to your helloWorld-methods must declare a dependency to the package in which the method is located.

    Usually each package uses is own class loading context.
    But declaring the dependency forces the class loader to load all packages affected in the lowest common class loader context.

    Can you share some error messages as well as some more details about your use case, please?

    Regards,
    Holger


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 3.  RE: Call a static global function

    Posted 12/15/15 02:56 PM

    In my previous expereince if we had to access bunch of methods throughout all the Packages on Integration server, we would package all the methods in to single class and then export the Java project from Eclipse as a Jar. We place this jar in the IS\packagename\code\jars\static folder. Not sure about 9.x or higher, you can try it.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 4.  RE: Call a static global function

    Posted 12/15/15 03:02 PM

    JOUBERT – I didn’t understand your question, can you please elaborate.

    Thanks,


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 5.  RE: Call a static global function

    Posted 12/16/15 05:00 AM

    Thanks for your replies. I would hop to avoid package my class and functions in an external Jar… but why not…

    To try to elaborate,

    I have a public class :

    
    package mypackage.utils.tests;
    
    public final class myTest_SVC
    {
    
    public static final void myTest(IData pipeline) throws ServiceException {
    }
    public static void helloWorld(String text)
    {
    ...
    }
    final static myTest_SVC _instance = new myTest_SVC();
    
    static myTest_SVC _newInstance() { return new myTest_SVC(); }
    
    static myTest_SVC _cast(Object o) { return (myTest_SVC)o; }
    }

    Now, from another class of package (in another directory), I would like to access helloWorld() function :

    
    package mypackage.utils.calls;
    import mypackage.utils.tests.myTest_SVC;
    
    public final class myCall_SVC
    {
    public static final void myCall(IData pipeline) throws ServiceException {
    // ... calling myTest_SVC.helloWorld(...);
    }
    }

    From the Import clause, I meet this error :

    The source was saved, but was not compiled due to the following errors:
    error: cannot find symbol
    import mypackage.utils.tests.myTest_SVC;
    …^
    symbol: class myTest_SVC
    location: class tests
    1 error

    Any idea ?

    Regards


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 6.  RE: Call a static global function

    Posted 12/16/15 08:58 AM

    Hi Akshith,

    this is still possible.

    But as long as the jar does not need to be loaded in main IS classpath it can be placed under code/jars/, where reloading the package is sufficient when jar changes.

    When the jar is located under code/jars/static, it is neccessary to shutdown and start the IS to get the changed jar loaded.

    Regards,
    Holger


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 7.  RE: Call a static global function

    Posted 12/16/15 11:26 AM

    Thanks for the confirmation Holger!

    As for the error that he is reporting, he might have to add the jar to the Designer Project\lib folder as well for Eclipse to recognize the import?


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 8.  RE: Call a static global function

    Posted 12/16/15 12:02 PM

    I thouht there is no need to add the Jar in the Project\lib, because the Eclipse completion added the import clause automatically in my myCall_SVC class.

    Thanks for your help guys :slight_smile:


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 9.  RE: Call a static global function

    Posted 12/16/15 12:09 PM

    Hi,

    eventually reloading the package where the static function is located might help to make sure that the class has been loaded.

    Adding the jar in Designer is not neccessary to get the source compiled on remote IS.

    Regards,
    Holger


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 10.  RE: Call a static global function

    Posted 12/17/15 05:17 AM


  • 11.  RE: Call a static global function

    Posted 01/21/16 06:42 AM

    Hi,

    I’ve made a test with an external JAR and all works well.

    But I have another need please, but I do not want to deal with another external JAR.

    I need to call a Java function (or java class) from anywhere… regardless the package in which the class is definied. (like service.invoke() does to access a service Flow…)

    • call a Java function inside the same package

      PACKAGE1.package1.classFolder1
      PACKAGE1.package1.classFolder2
      PACKAGE1.package1.classFolder3

      I would like to use a the function defined in classFolder1, and access it from classFolder2 and classFolder3

    • call a Java function from another package

      PACKAGE1.package1.classFolder1
      PACKAGE2.package2.classFolder1

      I would like to use a the function defined in the first packaqe, and access it from another package ?

    I suppose what I need is possible to do ?


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 12.  RE: Call a static global function

    Posted 01/21/16 08:03 AM

    Hi Cedric,

    add a Package Depency in the propeties of package 2 pointing to package 1 and reload package 1.
    This causes both packages to be reloaded.

    After that you should be able to consume the java service from package 1 in package 2.

    Regards,
    Holger


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 13.  RE: Call a static global function

    Posted 01/21/16 09:48 AM

    Thanks for your reply.
    What do you mean by “consume”… calling service.invoke() ?

    I’ve tried to add my depencies, but after reloading the 2 packages,
    I can’t import Packaqe1 from Package2, neither import Package2 from Package1.

    Am I missing something ?

    Regards


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 14.  RE: Call a static global function

    Posted 01/21/16 11:01 AM

    Hi Cedric,

    just add the import statements in the java service development for the classes (either IS java service or classes in external jar).

    Can you share the import statements?

    Regards,
    Holger


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 15.  RE: Call a static global function

    Posted 01/22/16 04:54 AM

    Hi Holger,

    In this thread, I’ve first had the need to share classes using an external Jar. I made what you explained me, all is working fine.

    Today, I have a new need : I do not want to use any external Jar.
    I’m trying to call a Java class method from packages both created in webMethods : Package1 and Package2.
    When I try to import the package2 in the class of Package1, the Package2 is not visible, I have the error :

    package package1.utils;
    import package2.* —> “error: package package2 does not exist”

    After adding the dependencies in the Package option, I thought that my import would work, but no.
    I do not understand.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 16.  RE: Call a static global function

    Posted 01/22/16 08:13 AM

    Hi Cedric,

    the package name ist not part of the class name.

    Check the code/source and code/classes directories in your package on the file system.

    The generated and compiled java code is stored there.

    Regards,
    Holger


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 17.  RE: Call a static global function

    Posted 01/27/16 12:20 PM

    Hi Holger,

    It’s ok for invoking the service package2 to consume from package1.

    But, calling a class method or a method in Package2, from a class in Package1 do not still working…
    Am I missing something ?


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods