11

I have deployed a web application to the Google app engine and my web service uses the jersey 1.14 framework. When I try to consume or invoke the web services on the GAE I get a java.lang.IncompatibleClassChangeError: Implementing class. I searched around and got to realize that jersey 1.14 depends on asm 3.1 and google app engine uses asm 4.0 and realize that I had to use JarJar to package the dependencies to fix this problem but I don't have a clue about how to do this with JarJar. The tutorial I found was very cryptic and geared towards experience programmers.So can someone post a tutorial that is geared towards a beginner or walk me through the steps to solve this problem.

Joel Dean
  • 2,444
  • 5
  • 32
  • 50

2 Answers2

16

Well this is quite late answer, but if someone crosses by may be it would help. I will take an example and explain this. jarjar can be used to repackage java libraries. it can be used to change namespace for example org.apache.common.codec needs to be changed to some_random_name.org.apache.common.codec. Download jarjar from jarjar download site later paste the jar file you want to change (myinjar.jar) and downloaded jarjar into one folder and run this command java -jar jarjar-1.4.jar process myrules.txt myinjar.jar myoutjar.jar in myrules.txt add these lines

rule org.apache.commons.codec.** some_random_name.org.apache.commons.codec.@1

the output myoutjar.jar will be saved into same folder and you can use it in your project without any conflicts

Dayan
  • 7,634
  • 11
  • 49
  • 76
  • am getting `Syntax error: Duplicate jar entries: META-INF/LICENSE.txt` – Edijae Crusar Jan 04 '17 at 17:22
  • gikarasojo maybe this [link](http://stackoverflow.com/questions/31912459/duplicate-lib-file-copied-in-apk-meta-inf-license-txt-error-in-andorid-studio) can help – krishna chaitanya Jan 04 '17 at 17:58
  • I have a somehow complicated case. i want to use some functionalities provided a library `m.jar` this library requires that i use a class `BindingProvider` which is found in package `javax` but is not in android. thus i had to download another jar called `android-ws-combine.jar`. when i added it in my module and tried to run it, i got the error `Error:trouble processing "javax/xml/XMLConstants.class":`. i thought repackaging `android-ws-combine.jar` will help but my other jar `m.jar` also throws some errors since it can't find `javax.BindingProvider` because i renamed `javax` package when repa – Edijae Crusar Jan 04 '17 at 18:57
  • maybe you shouldn't change android-ws-combine.jar, as repackaging it will change the namespace and your m.jar cannot find appropriate packages and will throw an error, can you just try to include that without repackaging and see if it still throws any error? – krishna chaitanya Jan 06 '17 at 01:42
  • This approach might be problematic because of SPI META-INF/services files (Jersey uses them heavily). AFAIK jarjar doesn't process them so when you merge the jars the information about service providers is lost. You should use solution provided in: https://stackoverflow.com/questions/19150811/what-is-a-fat-jar and https://stackoverflow.com/questions/11947037/what-is-an-uber-jar – MeTTeO Mar 09 '20 at 16:59
0

You can use jar command of jdk to extract and merge the jar files.
jar -xvf firstjar.jar .... It will extract the jar classes folder/package wise -com/pak1/pak2
Now same extract second jar and merge the both expanded folders
No you can create a single jar of merged class files.
jar -cvf mergedjar.jar [folders name [ex com org ...]], for details check how jar commands works.

Naveen Ramawat
  • 1,425
  • 1
  • 15
  • 27
  • 2
    This won't help, because at runtime classes with the same fully-qualified name will collide. _Jarjar_ does more than just merging the jars. I still have to get my head around it myself, though. – vadipp Jan 28 '14 at 11:32