SapJco 3.0.11 with Maven: It is not allowed to rename or repackage the original archive “sapjco3.jar”

天大地大妈咪最大 提交于 2019-12-07 13:59:24

问题


The current version of the sap jco connector enforces the name of the containing jar at runtime. This will lead to exceptions, if it doesn't match the name (sapjco3.jar).

JCo initialization fails with java.lang.ExceptionInInitializerError: Illegal JCo archive "sap-jco-win-amd-64-3.0.11.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar"

We wrapped these libraries and deployed them with a custom pom in our nexus repository. The standard maven build is unusable atm, as a result of this change/the standard maven way of naming artifacts.

The current workaround uses system scope for this dependency and copies the sapjco maven artifact to a specified folder within the project, as this is the only way to enforce the name of an jar file and also keep it in the build as a dependency. This works within the same module. One of the disadvantages of the system scope is the deactivated/failing resolution of transitive artifacts. We would need that, as the sap connector module is included in an application war module. As system scope dependencies aren't included in the packaged artifacts, we had to copy them to the web-inf/lib folder and add a classpath entry to the manifest.

The build works, when i start it from the parent/root module, but fails when it is started in submodules due to the system scope dependency. We could live with that solution for now, but i'm definitely not happy with it.

Is there a recommended way to use sapjco with maven or a simpler approach to produce platform dependent artifacts, which include the native library and the jar with a specified name? Is SAP reconsidering this check, as the previous versions did not include it?

Edit:

  • Other developers seem to have the same issue: http://scn.sap.com/blogs/gushakov/2013/04/05/using-jco-without-nwds
  • System scope is deprecated and not a longterm solution

回答1:


I had the same issue, and below is how I fixed it (in short work around it): 1. Run the command in command prompt

mvn install:install-file 
-Dfile=sapjco3.jar 
-DgroupId=com.company.sap 
-DartifactId=com.sap.conn.jco.sapjco 
-Dversion=1.0 
-Dpackaging=jar
  1. This will create a local artifact, or you can also create it in remote repository
  2. Download this dependency from maven as shown below:

    <dependency> <groupId>com.company.sap</groupId> <artifactId>com.sap.conn.jco.sapjco</artifactId> <version>1.0</version> </dependency>

This work around would avoid the sapjco3 error:

if (!jarname.equals("sapjco3.jar") 
&& !jarname.startsWith("com.sap.conn.jco") 
&& !jarname.equals("sapjco3_IDE.jar") 
&& Package.getPackage("org.apache.maven.surefire.booter") == null 
&& Package.getPackage("org.eclipse.jdt.internal.junit.runner") == null) {
    throw new ExceptionInInitializerError("Illegal JCo archive \"" + jarname + "\". It is not allowed to rename or repackage the original archive \"" + "sapjco3.jar" + "\".");
}


来源:https://stackoverflow.com/questions/24765243/sapjco-3-0-11-with-maven-it-is-not-allowed-to-rename-or-repackage-the-original

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!