Call a static method from another package

Hi,

I have a service flow SF1 that calls a service java SJ1 in the same package P1.

My service java SJ1 calls 2 common static methods which are defined in a third class in another package P2.

I’ve copied the .class of P2 to the classes folder of P1 for it to be abble to access the static methods.
(and added the P1 dependance to P2 in the Designer).

All works fine but in that configuration how to be sure that P2 will be accessible, and the static methods too please ?

I’m asking you this question because I’ve met some errors before it works :
→ P2.utils.myMethod(I)V (but I do not undestand the “I” and the “V”)

The error was like if the P2 or class was no accessible.

If you could help me please… I would like to avoid to break all :wink:

Regards

Hi Cedric,

there should be no need to copy the sources or classes from P2 to P1.

Just make sure that the dependency is set from P1 to P2 and both packages have been reloaded.

After that in the java service SJ1 add an import statement to the class in P2.

What was the exact error message for “P2.utils.myMethod(I)V”?

Regards,
Holger

I’ve tried many way, the only one which worked is to copy the source class from P2 to P1 (few month ago I’ve asked to the support an example on how a Java service package P1 car access to a java service defined on P2, they replied that I have to make the copy)

The exact message were : (mifTechnique si the P2 package :wink: )

Regards

Hi Cedric,

sounds really strange.

What is the error message from Error-Log or Designert for this?

Can you provide the signature of the setDebugMode-Method from the java.frag file?

To copy something to somewhere else is a bad idea generally.
What happens if there is a change to the source and it gets missed to copy it to the other package?

What is your IS and Java Version?
Any Fixes applied to IS?

Regards,
Holger

Yes Holger, I’m perfectly agree but I did not find any other way.
The support replied me this :

The error I’ve had has disappeared after I’ve reloaded all the packages, so I suppose the IS did not consider the dependance between packages and displayed me the below error. After reloading packages (and copying class) all was fine.

I’m in :
Product webMethods Integration Server
Version 9.8.0.0
Updates IS_9.8_Core_Fix7
IS_9.8_SPM_Fix1
Build Number 247
SSL Strong (128-bit)

and java version “1.8.0_91”.

Regards

Hi Cedric,

this reply (from SAG) does not match the description of this thread where you explain what you want to do.

When invoking an IS service (no matter if java or flow) from external java code you should create a wrapper code by selecting the right option in Designer and include this code in your external java code.

When invoking the external java code inside a service in IS it should be sufficient to add the package dependency, add the import statement and reload/recompile all the java artifacts.

When loading the same class several times within a dependent chain of packages the first one wins and the others are ignored.
Therefore there should be no neccessarity to copy it at all as it will not be loaded anyway.

See Java Services Developers Guide and/or Designer Users Guide for Details.

Regards,
Holger

Yes absolutely… my initial need was not to invoke a java service but to access native java methods.
But their message was a warning (not SAG supported).

After that, they gave me an example in which they explain me I need to copy the class in local.
Sorry for the missunderstanding : the copied class was to do only in Local for the Designer (not in any folder of the IS).

I’ve never succeed in compiling my code without copying the class in my local workspace.

as they as asked me :

Regards

Hi Cedric,

thanks for pointing that out.

But this should only be required for Local Service Development as Service Development projects are a featrure introduced with Local Service Development.

As we are still on wM 9.5 SP1 and are currently not licensed for Local Service Development for this version this was important information missing in the original post.

There have been quite some evolvements related to this in the last 5 releases therefore mentioning the version being referred to currently is neccessary for the community members to select the right “source of thruth’” for checking the documentation.

Regards,
Holger