ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to call "static void main" in an external jar

Post new topic  Reply to topic
 How to call "static void main" in an external jar « View previous topic :: View next topic » 
Author Message
simonalexander2005
PostPosted: Thu Nov 02, 2017 8:44 am    Post subject: How to call "static void main" in an external jar Reply with quote

Acolyte

Joined: 13 Jun 2016
Posts: 55

Hi,

Given a jar file containing a class
Code:
Start
in the package
Code:
com.test.pkg
, containing the method
Code:
public static void main(final String args[])
(so the jar file can be run by script using e.g.
Code:
java pkg-final.jar "test-argument"
, is the following ESQL correct for calling this method from an IIB flow?:

Code:
CREATE COMPUTE MODULE SandboxPOINTA_Compute
   CREATE FUNCTION Main() RETURNS BOOLEAN
   BEGIN
      -- CALL CopyMessageHeaders();
      -- CALL CopyEntireMessage();
      DECLARE TESTARG CHARACTER 'test-argument';
      CALL RunPKG(TESTARG);
      
      RETURN TRUE;
   END;
   /** Procedure to call PKG **/
   CREATE PROCEDURE RunPKG(INOUT TESTARG CHARACTER)
   LANGUAGE JAVA
   EXTERNAL NAME "com.test.pkg.Start.main";



Thank you for your help
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Nov 02, 2017 8:53 am    Post subject: Re: How to call "static void main" in an external Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

simonalexander2005 wrote:
s the following ESQL correct for calling this method from an IIB flow?:


Does it work? If so, it's right.

If it doesn't, post the errors / logs / relevant information and someone Java-literate will probably have some comments.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
simonalexander2005
PostPosted: Thu Nov 02, 2017 8:58 am    Post subject: Re: How to call "static void main" in an external Reply with quote

Acolyte

Joined: 13 Jun 2016
Posts: 55

Vitor wrote:
simonalexander2005 wrote:
s the following ESQL correct for calling this method from an IIB flow?:


Does it work? If so, it's right.

If it doesn't, post the errors / logs / relevant information and someone Java-literate will probably have some comments.


yes, sorry, I meant to say - I don't get any errors (I initially got "2943 Java class not found", then after restarting the broker I got "2946 The Java method could not be found", then I changed the parameter to INOUT); but nothing seems to happen either. A blank message is sent out of the compute node (obviously, as I don't copy anything from the input) so it's not erroring at all; but neither is the java class doing anything as far as I can tell) - although in posting this I have realised that the java class uses a config file, and a log4j config file -- I assume these also need to go onto the shared-classes folder?
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Nov 02, 2017 9:33 am    Post subject: Re: How to call "static void main" in an external Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

simonalexander2005 wrote:
although in posting this I have realised that the java class uses a config file, and a log4j config file -- I assume these also need to go onto the shared-classes folder?


I would imagine they need to go where the class expects them, in terms of relative path, though you might be able to do something with class loaders.

Someone with more Java than me will be along in a minute
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Nov 02, 2017 11:55 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

If it was me (and it isn't), and adding the files didn't help, I'd produce a wrapper that called this class but took an actual char as a parameter rather than the array. Try calling that and see what happens in the lack of more skilled advice.....
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
souciance
PostPosted: Mon Nov 06, 2017 12:08 pm    Post subject: Re: How to call "static void main" in an external Reply with quote

Disciple

Joined: 29 Jun 2010
Posts: 169

simonalexander2005 wrote:
Hi,

Given a jar file containing a class
Code:
Start
in the package
Code:
com.test.pkg
, containing the method
Code:
public static void main(final String args[])
(so the jar file can be run by script using e.g.
Code:
java pkg-final.jar "test-argument"
, is the following ESQL correct for calling this method from an IIB flow?:

Code:
CREATE COMPUTE MODULE SandboxPOINTA_Compute
   CREATE FUNCTION Main() RETURNS BOOLEAN
   BEGIN
      -- CALL CopyMessageHeaders();
      -- CALL CopyEntireMessage();
      DECLARE TESTARG CHARACTER 'test-argument';
      CALL RunPKG(TESTARG);
      
      RETURN TRUE;
   END;
   /** Procedure to call PKG **/
   CREATE PROCEDURE RunPKG(INOUT TESTARG CHARACTER)
   LANGUAGE JAVA
   EXTERNAL NAME "com.test.pkg.Start.main";



Thank you for your help


To be honest, running the main method inside IIB, I am not sure how well that well work. IIB is not an application server.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Nov 07, 2017 5:43 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

First of all I have no idea what the OP expects to see as a result. I would for sure not expect to see anything at all. After all the signature of the method is most probably
Code:
public static void main(String[] args)

So unless what happens withing the method is of some relevance and can be seen or traced, there is no way that you'd see anything in ESQL.

Second using log4J is not best practice. Best practice says use java.util.logging.
So if you want an output more similar to log4J you can just write your own logger formatter.... (and I have done so on the odd occasion)...

Hope it helps
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
simonalexander2005
PostPosted: Tue Nov 07, 2017 7:44 am    Post subject: Reply with quote

Acolyte

Joined: 13 Jun 2016
Posts: 55

souciance wrote:
To be honest, running the main method inside IIB, I am not sure how well that well work. IIB is not an application server.


That's what I'm trying to figure out - will it work or will I need to rewrite the java.

fjb_saper wrote:
First of all I have no idea what the OP expects to see as a result. I would for sure not expect to see anything at all. After all the signature of the method is most probably
Code:
public static void main(String[] args)

So unless what happens withing the method is of some relevance and can be seen or traced, there is no way that you'd see anything in ESQL.


You're correct about the signature - but the code itself takes some actions - moves a file from one location to another as an indicator of success - and that can be traced by IIB. I agree that all I can say from the ESQL's perspective is that the java has been triggered.

In the console for the execution group, I am seeing:
Quote:

"ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console."


Which I take to mean that the code is being triggered, but it can't find the config file. I have tried putting it:

    -in the same folder as the jar (shared-classes)
    -inside the bar file itself
    -in the same folder as the console.txt for the execution group


I think I understand the theory that the jvm is running somewhere, and the properties file needs to be relative to the root of that somehow? So how do I figure out where I need to put the config file?

fjb_saper wrote:

Second using log4J is not best practice. Best practice says use java.util.logging.
So if you want an output more similar to log4J you can just write your own logger formatter.... (and I have done so on the odd occasion)...


I am attempting to use a jar file which I was provided, without editing the code at all - it came with log4j and so I'm stuck with using it, if I can.
    Back to top
    View user's profile Send private message
    simonalexander2005
    PostPosted: Tue Nov 07, 2017 8:03 am    Post subject: Reply with quote

    Acolyte

    Joined: 13 Jun 2016
    Posts: 55

    Found it! for anyone looking in the future, the required directory (on Windows) is (for my version of IIB): C:\Program Files (x86)\IBM\MQSI\9.0.0.6\bin
    Back to top
    View user's profile Send private message
    fjb_saper
    PostPosted: Tue Nov 07, 2017 8:59 am    Post subject: Reply with quote

    Grand High Poobah

    Joined: 18 Nov 2003
    Posts: 20696
    Location: LI,NY

    simonalexander2005 wrote:


    In the console for the execution group, I am seeing:
    Quote:

    "ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console."


    Which I take to mean that the code is being triggered, but it can't find the config file. I have tried putting it:

      -in the same folder as the jar (shared-classes)
      -inside the bar file itself
      -in the same folder as the console.txt for the execution group


    I think I understand the theory that the jvm is running somewhere, and the properties file needs to be relative to the root of that somehow? So how do I figure out where I need to put the config file?

    fjb_saper wrote:

    Second using log4J is not best practice. Best practice says use java.util.logging.
    So if you want an output more similar to log4J you can just write your own logger formatter.... (and I have done so on the odd occasion)...


    I am attempting to use a jar file which I was provided, without editing the code at all - it came with log4j and so I'm stuck with using it, if I can.

      Best practice says: Use a configurable service to point out where the config file is. Make that location absolute. Use it in the init method when initializing your log4J.
      This way you don't have to worry about location of config file not being where you expect it should be when given in relative terms.
      _________________
      MQ & Broker admin
      Back to top
      View user's profile Send private message Send e-mail
      Display posts from previous:   
      Post new topic  Reply to topic Page 1 of 1

      MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to call "static void main" in an external jar
      Jump to:  



      You cannot post new topics in this forum
      You cannot reply to topics in this forum
      You cannot edit your posts in this forum
      You cannot delete your posts in this forum
      You cannot vote in polls in this forum
      Protected by Anti-Spam ACP
       
       


      Theme by Dustin Baccetti
      Powered by phpBB © 2001, 2002 phpBB Group

      Copyright © MQSeries.net. All rights reserved.