Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

maven

sap

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
like image 840
Alexander Pilch Avatar asked Oct 31 '22 20:10

Alexander Pilch


1 Answers

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" + "\".");
}
like image 167
Sambit Swain Avatar answered Nov 08 '22 09:11

Sambit Swain