2

Hi I am facing the below while running munit with maven code.

I have a flow containing SAP connector, then done the munit for the flow and trying to run the munit with maven, getting the below exception, need help.

[ERROR] Failed to shut down registry cleanly: org.mule.Registry.Spring
org.mule.api.lifecycle.LifecycleException: Failed to invoke lifecycle phase "dispose" on object: SapConnector$$EnhancerByCGLIB$$1f197d8f
{
  name=SAP_08
  lifecycle=not in lifecycle
  this=298e706
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=false
  supportedProtocols=[sap]
  serviceOverrides=<none>
}

    at org.mule.lifecycle.phases.DefaultLifecyclePhase.applyLifecycle(DefaultLifecyclePhase.java:248)
    at org.mule.lifecycle.phases.MuleContextDisposePhase.applyLifecycle(MuleContextDisposePhase.java:102)
    at org.mule.config.spring.SpringRegistryLifecycleManager$SpringContextDisposePhase.applyLifecycle(SpringRegistryLifecycleManager.java:141)
    at org.mule.lifecycle.RegistryLifecycleCallback.doApplyLifecycle(RegistryLifecycleCallback.java:91)
    at org.mule.lifecycle.RegistryLifecycleCallback.onTransition(RegistryLifecycleCallback.java:67)
    at org.mule.lifecycle.RegistryLifecycleManager.invokePhase(RegistryLifecycleManager.java:140)
    at org.mule.lifecycle.RegistryLifecycleManager.fireLifecycle(RegistryLifecycleManager.java:111)
    at org.mule.registry.AbstractRegistry.dispose(AbstractRegistry.java:68)
    at org.mule.registry.AbstractRegistryBroker$2.onTransition(AbstractRegistryBroker.java:69)
    at org.mule.registry.AbstractRegistryBroker$2.onTransition(AbstractRegistryBroker.java:64)
    at org.mule.lifecycle.RegistryLifecycleManager.invokePhase(RegistryLifecycleManager.java:140)
    at org.mule.lifecycle.RegistryBrokerLifecycleManager.fireDisposePhase(RegistryBrokerLifecycleManager.java:82)
    at org.mule.registry.AbstractRegistryBroker.dispose(AbstractRegistryBroker.java:63)
    at org.mule.registry.MuleRegistryHelper.fireLifecycle(MuleRegistryHelper.java:137)
    at org.mule.lifecycle.MuleContextLifecycleManager$MuleContextLifecycleCallback.onTransition(MuleContextLifecycleManager.java:91)
    at org.mule.lifecycle.MuleContextLifecycleManager$MuleContextLifecycleCallback.onTransition(MuleContextLifecycleManager.java:87)
    at org.mule.lifecycle.MuleContextLifecycleManager.invokePhase(MuleContextLifecycleManager.java:69)
    at org.mule.lifecycle.MuleContextLifecycleManager.fireLifecycle(MuleContextLifecycleManager.java:61)
    at org.mule.DefaultMuleContext.dispose(DefaultMuleContext.java:345)
    at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:230)
    at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:81)
    at org.mule.munit.runner.MunitMuleContextFactory.createMuleContext(MunitMuleContextFactory.java:85)
    at org.mule.munit.runner.MuleContextManager.createMule(MuleContextManager.java:97)
    at org.mule.munit.runner.MuleContextManager.startMule(MuleContextManager.java:56)
    at org.mule.munit.runner.mule.MunitSuiteRunner.<init>(MunitSuiteRunner.java:42)
    at org.mule.MUnitMojo.buildRunnerFor(MUnitMojo.java:311)
    at org.mule.MUnitMojo.doExecute(MUnitMojo.java:173)
    at org.mule.MUnitMojo.execute(MUnitMojo.java:122)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive "sapjco3-3.0.13.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar".
    at com.sap.conn.jco.rt.MiddlewareJavaRfc.<clinit>(MiddlewareJavaRfc.java:230)
    at com.sap.conn.jco.rt.DefaultJCoRuntime.initialize(DefaultJCoRuntime.java:98)
    at com.sap.conn.jco.rt.JCoRuntimeFactory.<clinit>(JCoRuntimeFactory.java:23)
    at com.sap.conn.jco.rt.RuntimeEnvironment.<init>(RuntimeEnvironment.java:43)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.lang.Class.newInstance(Class.java:379)
    at com.sap.conn.jco.ext.Environment.getInstance(Environment.java:155)
    at com.sap.conn.jco.ext.Environment.isDestinationDataProviderRegistered(Environment.java:401)
    at com.mulesoft.mule.transport.sap.jco3.SapJcoFactory.startup(SapJcoFactory.java:198)
    at com.mulesoft.mule.transport.sap.jco3.SapJcoFactory.<clinit>(SapJcoFactory.java:45)
    at com.mulesoft.mule.transport.sap.SapConnector.doDispose(SapConnector.java:198)
    at com.mulesoft.mule.transport.sap.SapConnector$$EnhancerByCGLIB$$1f197d8f.CGLIB$doDispose$4(<generated>)
    at com.mulesoft.mule.transport.sap.SapConnector$$EnhancerByCGLIB$$1f197d8f$$FastClassByCGLIB$$c6f1beab.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
    at org.mule.modules.interceptor.connectors.ConnectorMethodInterceptor.intercept(ConnectorMethodInterceptor.java:48)
    at com.mulesoft.mule.transport.sap.SapConnector$$EnhancerByCGLIB$$1f197d8f.doDispose(<generated>)
    at org.mule.transport.AbstractConnector$4.onTransition(AbstractConnector.java:596)
    at org.mule.transport.AbstractConnector$4.onTransition(AbstractConnector.java:592)
    at org.mule.lifecycle.AbstractLifecycleManager.invokePhase(AbstractLifecycleManager.java:138)
    at org.mule.transport.ConnectorLifecycleManager.fireDisposePhase(ConnectorLifecycleManager.java:89)
    at org.mule.transport.AbstractConnector.dispose(AbstractConnector.java:591)
    at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.mule.lifecycle.phases.DefaultLifecyclePhase.applyLifecycle(DefaultLifecyclePhase.java:237)
    ... 48 more
[INFO] Closing org.mule.munit.runner.spring.config.MunitApplicationContext@53830ac9: startup date [Tue Sep 20 16:30:07 IST 2016]; root of context hierarchy
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 38.910s
[INFO] Finished at: Tue Sep 20 16:30:19 IST 2016
[INFO] Final Memory: 76M/269M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.mulesoft.munit.tools:munit-maven-plugin:1.1.0:test (test) on project mule_onprem_to_sap: Execution test of goal com.mulesoft.munit.tools:munit-maven-plugin:1.1.0:test failed: org.mule.api.config.ConfigurationException: Failed to invoke lifecycle phase "initialise" on object: SapConnector$$EnhancerByCGLIB$$1f197d8f
[ERROR] {
[ERROR] name=SAP_08
[ERROR] lifecycle=not in lifecycle
[ERROR] this=298e706
[ERROR] numberOfConcurrentTransactedReceivers=4
[ERROR] createMultipleTransactedReceivers=true
[ERROR] connected=false
[ERROR] supportedProtocols=[sap]
[ERROR] serviceOverrides=<none>
[ERROR] }
[ERROR] (org.mule.api.lifecycle.InitialisationException): org/mule/module/reboot/EEMuleContainerBootstrap: org.mule.module.reboot.EEMuleContainerBootstrap
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Ankit Prakash
  • 37
  • 1
  • 7
  • 1
    Providing relevant parts (or all) of your pom would be helpful – alexbt Sep 20 '16 at 11:28
  • "JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive "sapjco3-3.0.13.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar"." sounds quite clear... – vwegert Sep 20 '16 at 11:40

3 Answers3

0

@Ankit Prakash this is the SAP maven dependency issue.

You must follow the steps described below in order to overcome the limitations imposed both by SAP JCo and Maven, and get a project that will be able to run in Studio:

1 - Install resources to local Maven repository

The commands specified below are required to install the jars and the native libraries into you local Maven repository. Note that we are showing how to install the native libraries for MaOS 64-bits, Linux x86 64-bits and Windows 64-bits.

sapidoc3.jar, version 3.0.12: mvn install:install-file -DgroupId=com.sap.conn.idoc -DartifactId=sapidoc3 -Dversion=3.0.12 -Dpackaging=jar -Dfile=sapidoc3.jar

sapjco3.jar, version 3.0.14: mvn install:install-file -DgroupId=com.sap.conn.jco -DartifactId=sapjco3 -Dversion=3.0.14 -Dpackaging=jar -Dfile=sapjco3.jar

Native library MacOS 64 bits, version 3.0.14: mvn install:install-file -DgroupId=com.sap.conn.jco -DartifactId=sapjco3 -Dversion=3.0.14 -Dclassifier=darwinintel64 -Dpackaging=jnilib -Dfile=libsapjco3.jnilib

Native library Linux x86 64 bits, version 3.0.14: mvn install:install-file -DgroupId=com.sap.conn.jco -DartifactId=sapjco3 -Dversion=3.0.14 -Dclassifier=linuxx86_64 -Dpackaging=so -Dfile=libsapjco3.so

Native library Windows AMD 64 bits, version 3.0.14: mvn install:install-file -DgroupId=com.sap.conn.jco -DartifactId=sapjco3 -Dversion=3.0.14 -Dclassifier=ntamd64 -Dpackaging=dll -Dfile=sapjco3.dll

After following the steps described above, the folder that contains the resources for sapjco3, version 3.0.14, will include the following files:

~/.m2/repository/com/sap/conn/jco/sapjco3/3.0.14

  • sapjco3-3.0.14-darwinintel64.jnilib
  • sapjco3-3.0.14.jar
  • sapjco3-3.0.14-NTAMD64.dll
  • sapjco3-3.0.14-linuxx86_64.so
  • sapjco3-3.0.14.pom

Similarly, the folder that contains the resources for sapidoc3, version 3.0.12, will include the following files:

~/.m2/repository/com/sap/conn/idoc/sapidoc3/3.0.12

  • sapidoc3-3.0.12.jar
  • sapidoc3-3.0.12.pom

2 - Use the provided POM

Use the POM attached as a base for all you applications using the MuleSoft Connector for SAP Solutions.

Note that we are using profiles that are being activated automatically, based on the operating system and architecture, to set the name of the native library that will be used.

Also we created a profile named studio, that you must activate whenever you need to include all the jars and the corresponding native library to the deployment archive that will be generated whenever you run the command maven clean package.

3 - Copy the native library to your Studio project

Create a directory called lib at the root level of your mavenized Studio project and copy there the native library. When building and packaging the application, the content of that folder won't be included in the deployment archive.

4 - Change the Maven Settings to activate the studio profile

  • Go to Run -> Run Configurations...
  • Select your mavenized project
  • Go to the Maven Settings tab
  • Enter the following argument: -Druntime=studio

Hope this helps.

AnupamBhusari
  • 2,395
  • 2
  • 14
  • 22
  • Thanks for reply but i already tried the above method but still the result is same for deploying munit with maven. If trying to skip munit test cases by using -DskipMunitTests, the code gets deployed. Can you provide the alternate suggestions. – Ankit Prakash Sep 20 '16 at 12:09
  • I have mocked the SAP Connector in the munit test case. When i tried running the munit test case "Run as MUnit Test, it is working. When i tried running the complete application by using maven command "mvn clean package -DskipMunitTests" it is deploying but when i am trying the maven command "mvn clean package" i am facing the issue like Illegal JCO archinve... – Ankit Prakash Sep 20 '16 at 15:02
  • **@AnupamBhusari** , I got the solution for this issue anyway thanks for you suggestion and help as well. – Ankit Prakash Mar 07 '17 at 09:09
  • @AnkitPrakash Please share how you fixed the issue to help other users that might run into the same problem. – CountD May 29 '17 at 15:06
  • Link to the original source: https://support.mulesoft.com/s/article/How-to-use-Maven-to-add-SAP-Connector-dependencies – CountD May 29 '17 at 15:09
0

It's an old question but just in case any one hits this issue then add below dependency. Note the scope is test as it is not needed during runtime.

    <dependency>
        <groupId>com.mulesoft.muleesb.modules</groupId>
        <artifactId>mule-module-boot-ee</artifactId>
        <scope>test</scope>
    </dependency>
Manik Magar
  • 1,403
  • 2
  • 10
  • 20
-1

I got the answer for Munit issue with SAP jars.

Please follow below steps for fixing this issue:-

  1. Add the SAP libraries to the classpath:

    (a) Navigate to Build Path > Configure Build Path

    (b) In the Libraries tab, click the Add Library …​ button

    (c) Select Anypoint Connectors Dependencies

    (d) Select the SAP Connector option.

  2. You may also need to make the java.library.path point to the folder where the native libraries are located. The MUnit Studio plugin will try to find these native libraries and configure them automatically when you try to run your tests. In case they are not found, you need to add the following vm argument in the run configuration:

    (a) In Studio’s top navigation bar, click run

    (b) Click Run Configurations…​

    (c) Select the Arguments tab

    (d) In the VM Arguments dialog box, type the path to your libraries with the

    java.library.path argument.
    Example: -Djava.library.path=path/to/lib
    

JVM Argument

From Maven

One way of adding the libraries to the classpath is using the additionalClasspathElements parameter in the maven plugin. You can provide the path to each of the SAP libraries that you want to add:

<additionalClasspathElements>
    <additionalClasspathElement>/path/to/lib/sapjco3.jar</additionalClasspathElement> 
    <additionalClasspathElement>/path/to/lib/sapidoc3.jar</additionalClasspathElement>
</additionalClasspathElements>

Note:-If there is already a sap dependency in the pom, but the library name doesn’t match SAP naming restrictions, you may need to exclude them from the test run. This way the libraries added with the additionalClassPathElement parameter will take precedence:

<classpathDependencyExcludes> 
    <classpathDependencyExclude>com.sap.conn.idoc:sapidoc3</classpathDependencyExclude>  
    <classpathDependencyExclude>com.sap.conn.jco:sapjco3</classpathDependencyExclude>
</classpathDependencyExcludes>

Additionally, you need to make the java.library.path property point to the native libraries directory, similar to how it’s done in Studio. To accomplish this, you can use the argLine parameter to add the additional vm argument.

<argLines>
    <argLine>-Djava.library.path=/path/to/native/lib/folder</argLine>
</argLines>

I hope the above description will be helpful.

For more details refer link:- Munit with SAP jars

Ankit Prakash
  • 37
  • 1
  • 7