Modularization is an important concept of programming. So, when I wanted to create a Java Service in webMethods’ Integration Server today, I wanted to re-use my existing Java code that already provided the feature I wanted to publish as a Service. However, this is not as easy as it sounds 😉 Here are the steps you need to perform to get your already existing Java code working in a Java Service:
- Compile and bundle your external Java project into a JAR file, e.g. using Apache Ant.
- Copy this JAR file into the subfolder
code\jars\
of your package on Integration Server and reload the package. Example path:[...]\SoftwareAG\IntegrationServer\packages\YOURPACKAGE\code\jars\
. Now, IS is able to use the JAR and automatically puts it into the package’s CLASSPATH. - Copy the JAR file into the subfolder
lib\
of your local Java project (in your local Eclipse workspace) and add it to the Eclipse project’s CLASSPATH, e.g. by adding<classpathentry kind="lib" path="lib/MyExternalProject.jar"/>
to.classpath
. Now, Software AG Designer (i.e. Eclipse) is able to resolve the external classes and can compile the code correctly, provide code completion etc. -
import
the needed packages from your external project and use the classes in your code. Here’s some example code from the resulting Java Service:package XML.Services; import com.wm...; // all webMethods imports import it.macke.tools.saxxmlvalidator.SaxXmlValidator; // import from your external project public final class ValidateXML_SVC { /** * The primary method for the Java service * * @param pipeline * The IData pipeline * @throws ServiceException */ public static final void ValidateXML(IData pipeline) throws ServiceException { xml = ISPipelineHelper.getInputParameter(pipeline, "xmlStream"); schema = ISPipelineHelper.getInputParameter(pipeline, "schemaStream"); validateXML(); } // --- <<IS-BEGIN-SHARED-SOURCE-AREA>> --- private static InputStream xml; private static InputStream schema; private static boolean isValid; private static String validationError; private static void validateXML() throws ServiceException { isValid = true; validationError = ""; // now you can use your own classes SaxXmlValidator validator = new SaxXmlValidator(xml, schema); try { validator.validate(); } catch (XmlNotValidException e) { isValid = false; validationError = e.getMessage(); } catch (Exception e) { throw new ServiceException(e); } } // --- <<IS-END-SHARED-SOURCE-AREA>> --- }
Hi Stefan,
thanks for the infos. For WM it’s hard to find useful information. The official documentation is imo very disappointing. Currently I battle with 9.12 for the same problem and without much success. Only for pt 3 I need some help. BTW I use IntelliJ for the jar-file and the Designer for service development. Where do I find the Eclipse CLASSPATH and the lib\ folder?
Thanks
Martin
Hi Martin,
I’m talking about the Java project that SAG Desginer creates for you. If you program a Java Service, there will automatically be a Java project where the sources are stored in your SAG workspace. In this folder you’ll find
.classpath
andlib
. Perhaps you need to enable Local Versioning in SAG Designer by right clicking on the IS Package and selecting the appropriate item in the context menu.Best regards,
Stefan