Menu

Support SAP JCo 3.0.11

Help
2014-10-30
2019-05-15
  • Thomas Klöber

    Thomas Klöber - 2014-10-30

    We would like to use Hibersap together with the latest SAP JCo which is version 3.0.11.
    However, to some extremly strange quirk SAP decided to name the jar file sapjco3.jar and also hardcoded this name into its code and verify it at startup.

    This in turn means we can't set up a proper maven dependency for sapjco and its current version.
    Renaming the jar to sapjco-3.0.11.jar leads to a runtime exception: "java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive "sapjco-3.0.11.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar"."

    Has anyone come up with a solution for this?

     
  • Carsten Erker

    Carsten Erker - 2014-10-30

    Hi Thomas,
    this is really a strange thing which SAP does here. I haven't tried with JCo 3.0.11 yet. As a first workaround you could try configuring the maven-dependency-plugin with the stripVersion attribute, which should have the effect that all version numbers of the dependent libs are stripped. Right now I can't test it myself, but maybe it's a starting point.
    See: http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html#stripVersion

     
  • Thomas Klöber

    Thomas Klöber - 2014-11-03

    HI Carsten,

    thanks for your reply. I actually got the same from SAP:

    "The recent JCo release includes an additional technical check by
    intention and will not be removed. It was never allowed to rename or
    repackage SAP software archives and because we ran into issues within
    some customer scenarios who did nevertheless, we will now prevent this
    technically with adding a check. Renaming or repackaging of the JCo
    archives may cause strange error situations and results in upatchable
    installations.
    It should be possible to adapt the project build environment for also
    dealing with the new JCo archives.
    The maven-dependency-plugin configuration in pom.xml file can be
    modified with adding the option <stripVersion>true </stripVersion>
    for copying the JCo artifacts.
    Further information is available externally at
    http://maven.apache.org/plugins/maven-dependency-plugin/usage.html .
    Please note that this is not an issue with SAP software but with Maven
    build environment configuration only. So if the above information is
    not sufficient for resolving the issue, I would like to ask you to
    address the Maven community for further help and assistance with this."

    Still doesn't make a lot of sense to me, but there you are.
    Right now I'm batlling with getting this into my pom's, but without much success so far...

     
  • comtoexe

    comtoexe - 2015-07-10

    I can't run jar file after maven package.
    Error message:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

    steps:

    N:\JAVA-Project\workspace\z_hibersap_1>mvn clean
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building z_hibersap_1 1.0.0
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ z_hibersap_1 ---
    [INFO] Deleting N:\JAVA-Project\workspace\z_hibersap_1\target
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.348 s
    [INFO] Finished at: 2015-07-10T13:32:13+08:00
    [INFO] Final Memory: 5M/15M
    [INFO] ------------------------------------------------------------------------

    N:\JAVA-Project\workspace\zhibersap_1>mvn package
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building z_hibersap_1 1.0.0
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ z_hibersap
    _1 ---
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
    . build is platform dependent!
    [INFO] Copying 1 resource
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ z_hibersap_1 --
    -
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
    d is platform dependent!
    [INFO] Compiling 90 source files to N:\JAVA-Project\workspace\z_hibersap_1\targe
    t\classes
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ z

    hibersap_1 ---
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
    . build is platform dependent!
    [INFO] Copying 0 resource
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ z_hiber
    sap_1 ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
    d is platform dependent!
    [INFO] Compiling 1 source file to N:\JAVA-Project\workspace\z_hibersap_1\target\ test-classes
    [INFO]
    [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ z_hibersap_1 ---
    [INFO] Surefire report directory: N:\JAVA-Project\workspace\z_hibersap_1\target\ surefire-reports


    T E S T S

    Results :

    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

    [INFO]
    [INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ z_hibersap_1 ---
    [INFO] Building jar: N:\JAVA-Project\workspace\zhibersap_1\target\z_hibersap_1-
    1.0.0.jar
    [INFO]
    [INFO] --- maven-dependency-plugin:2.8:copy-dependencies (copy) @ z_hibersap_1 -
    --
    [INFO] Copying sapjco3-3.0.12.jar to N:\JAVA-Project\workspace\z_hibersap_1\targ
    et\lib\sapjco3.jar
    [INFO] Copying fest-util-1.1.6.jar to N:\JAVA-Project\workspace\z_hibersap_1\tar
    get\lib\fest-util.jar
    [INFO] Copying hamcrest-core-1.3.jar to N:\JAVA-Project\workspace\z_hibersap_1\t
    arget\lib\hamcrest-core.jar
    [INFO] Copying hibernate-validator-4.0.2.GA.jar to N:\JAVA-Project\workspace\z_h
    ibersap_1\target\lib\hibernate-validator.jar
    [INFO] Copying log4j-1.2.14.jar to N:\JAVA-Project\workspace\z_hibersap_1\target
    \lib\log4j.jar
    [INFO] Copying cglib-nodep-2.2.2.jar to N:\JAVA-Project\workspace\z_hibersap_1\t
    arget\lib\cglib-nodep.jar
    [INFO] Copying slf4j-api-1.5.6.jar to N:\JAVA-Project\workspace\z_hibersap_1\tar
    get\lib\slf4j-api.jar
    [INFO] Copying stax-api-1.0-2.jar to N:\JAVA-Project\workspace\z_hibersap_1\targ
    et\lib\stax-api.jar
    [INFO] Copying commons-logging-1.2.jar to N:\JAVA-Project\workspace\z_hibersap_1
    \target\lib\commons-logging.jar
    [INFO] Copying junit-4.11.jar to N:\JAVA-Project\workspace\z_hibersap_1\target\l
    ib\junit.jar
    [INFO] Copying commons-lang-2.6.jar to N:\JAVA-Project\workspace\z_hibersap_1\ta
    rget\lib\commons-lang.jar
    [INFO] Copying activation-1.1.jar to N:\JAVA-Project\workspace\z_hibersap_1\targ
    et\lib\activation.jar
    [INFO] Copying objenesis-1.3.jar to N:\JAVA-Project\workspace\z_hibersap_1\targe
    t\lib\objenesis.jar
    [INFO] Copying easymock-3.2.jar to N:\JAVA-Project\workspace\z_hibersap_1\target
    \lib\easymock.jar
    [INFO] Copying jaxb-api-2.1.jar to N:\JAVA-Project\workspace\z_hibersap_1\target
    \lib\jaxb-api.jar
    [INFO] Copying slf4j-log4j12-1.7.12.jar to N:\JAVA-Project\workspace\z_hibersap

    1\target\lib\slf4j-log4j12.jar
    [INFO] Copying validation-api-1.1.0.jar to N:\JAVA-Project\workspace\zhibersap
    1\target\lib\validation-api.jar
    [INFO] Copying jaxb-impl-2.1.3.jar to N:\JAVA-Project\workspace\z_hibersap_1\tar
    get\lib\jaxb-impl.jar
    [INFO] Copying fest-assert-1.4.jar to N:\JAVA-Project\workspace\z_hibersap_1\tar
    get\lib\fest-assert.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.692 s
    [INFO] Finished at: 2015-07-10T13:32:28+08:00
    [INFO] Final Memory: 16M/41M
    [INFO] ------------------------------------------------------------------------

    N:\JAVA-Project\workspace\z_hibersap_1>java -jar target\z_hibersap_1-1.0.0.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lo
    gging/LogFactory
    at org.hibersap.configuration.Configuration.<clinit>(Configuration.java:
    49)
    at org.hibersap.examples.flightlist.HibersapTest.createSessionManager(Hi
    bersapTest.java:15)
    at org.hibersap.examples.flightlist.HibersapTest.showFlightList(Hibersap
    Test.java:20)
    at org.hibersap.examples.flightlist.HibersapTest.main(HibersapTest.java:
    66)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFacto
    ry
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

     

    Last edit: comtoexe 2015-07-10
  • Carsten Erker

    Carsten Erker - 2015-07-13

    @comtoexe: It's a bit hard without seeing the pom.xml, so I guess:

    Do you copy all your dependencies yourself to target/lib?: If so, are you sure all these are added to your classpath?

    If you try to work around the SAP-JCo-Problem, try to manually handle just the Hibersap lib and rely on Maven for the rest (adding the needed libs as Maven dependencies). So you just have to do the manual copy & classpath process for the JCo lib.

     

    Last edit: Carsten Erker 2015-07-13
  • Carsten Erker

    Carsten Erker - 2015-07-13

    One approach is to download just sapjco3.jar from the local Maven repo using the maven-dependencies-plugin to, e.g. target/lib renaming it to sapjco3.jar and then add it to the project dependencies like this:

    <dependency>
    <groupId>org.hibersap</groupId>
    <artifactId>sapjco3</artifactId>
    <version>3.0.12</version>
    <scope>system</scope>
    <systemPath>${project.build.directory}/target/lib/sapjco3.jar</systemPath>
    </dependency>

     
  • Carsten Erker

    Carsten Erker - 2017-01-30

    The above outlined solution with a system dependency is far from being ideal and can still get very complicated, especially in a multi module project.

    Decompiling the JCo code, I found another - not perfect, but in my opinion better - workaround:

    The check in JCo allows the jar to either be named "sapjco3.jar", to start with "com.sap.conn.jco", or to be named "sapjco3_IDE.jar". So for now I deploy the JCo jar to the Maven repository with a Maven artifactId of "com.sap.conn.jco.sapjco3" and it works.

    We need to keep in mind though that this is JCo internal code that can change with any new release.

    So this is not a perfect solution either, but IMO the easiest to achieve and is well aligned with the way we usually use Maven.

     

    Last edit: Carsten Erker 2017-03-08
    • xuefei

      xuefei - 2019-05-15

      Hi Carsten,i follow your solution and do it like below

      first,deploy the jar to the maven

      mvn -X deploy:deploy-file -Durl=http://192.168.0.102:8081/repository/falcon-releases/ -Dfile=sapjco3.jar -DgroupId=com.sap.conn.jco -DartifactId=com.sap.conn.jco.sapjco3  -DrepositoryId=falcon-releases -Dversion=3.0.14
      

      in pom.xml

      <dependency>
                  <groupId>com.sap.conn.jco</groupId>
                  <artifactId>com.sap.conn.jco.sapjco3</artifactId>
                  <version>3.0.14</version>
      </dependency>
      

      but when i start the server(developed in springboot),the new exception occur like below:
      JCo initialization failed with java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path

      Caused by: java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
          at com.sap.conn.jco.rt.MiddlewareJavaRfc.<clinit>(MiddlewareJavaRfc.java:230) ~[com.sap.conn.jco.sapjco3-3.0.14.jar:20151217 0331 [3.0.14 (2015-12-16)]]
          at com.sap.conn.jco.rt.DefaultJCoRuntime.initialize(DefaultJCoRuntime.java:99) ~[com.sap.conn.jco.sapjco3-3.0.14.jar:20151217 0331 [3.0.14 (2015-12-16)]]
          at com.sap.conn.jco.rt.JCoRuntimeFactory.<clinit>(JCoRuntimeFactory.java:23) ~[com.sap.conn.jco.sapjco3-3.0.14.jar:20151217 0331 [3.0.14 (2015-12-16)]]
          at com.sap.conn.jco.rt.RuntimeEnvironment.<init>(RuntimeEnvironment.java:43) ~[com.sap.conn.jco.sapjco3-3.0.14.jar:20151217 0331 [3.0.14 (2015-12-16)]]
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_171]
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_171]
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_171]
          at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_171]
          at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_171]
          at com.sap.conn.jco.ext.Environment.getInstance(Environment.java:155) ~[com.sap.conn.jco.sapjco3-3.0.14.jar:20151217 0331 [3.0.14 (2015-12-16)]]
          at com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(Environment.java:259) ~[com.sap.conn.jco.sapjco3-3.0.14.jar:20151217 0331 [3.0.14 (2015-12-16)]]
          at nariis.userorg.management.jco.RFCManager.setJCOEnviroment(RFCManager.java:43) ~[classes/:?]
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
          at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
      

      can u help me ,than u

       
  • Chris Fouts

    Chris Fouts - 2018-07-23

    Hi Carsten, I'm just now experiencing this. So what do you mean to have an artifactId of com.sap.conn.jco.sapjco3? You mean, if pom.xml

    <artifactId>com.sap.conn.jco.sapjco3</artifactId>

    Can you please post your whole deploy command line, or pom file for deploy including groupId and version? Then post how you build the dependency to get the artifact (with long artifactId) you just deployed?

    Note we're using Gradle so I'm having to translate Maven (pom) to Gradle (build.gradle)

     

    Last edit: Chris Fouts 2018-07-23
    • Carsten Erker

      Carsten Erker - 2018-07-25

      Hi Chris,

      you can install the SAP-JCo library like described in the Hibersap documentation:
      http://hibersap.org/documentation/reference/#the-sap-java-connector-jco

      Alternatively, you can deploy it with the mentioned groupId/artifactId/version to an enterprise Maven repo like Nexus or Artifactory.

      And then declare the Gradle dependency with the coordinates org.hibersap:com.sap.conn.jco.sapjco3:3.0.15 in compile scope.

      Of course you can use a different version and also a different groupId if you like.

       

Log in to post a comment.