首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JarJar不重命名引用

JarJar不重命名引用
EN

Stack Overflow用户
提问于 2017-04-09 08:20:27
回答 1查看 1.3K关注 0票数 4

我正在使用Google的jarjar重新打包应用程序的fat jar中的依赖项。在运行重新打包的jar时,我得到了NoClassDefFoundError,例如:

代码语言:javascript
复制
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/classic/LoggerContext
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.LoggerContext

我对重新打包的jar进行了解压缩,并看到导入语句和代码中对依赖项的引用没有被重构。我哪里出问题了?

以下是我运行jarjar的方式:

代码语言:javascript
复制
java -jar jarjar-1.4.jar process repackageRules.txt myApp.jar app_repackaged.jar

我在repackageRules.txt中列出了一些规则:

代码语言:javascript
复制
rule javassist.** company.@0
rule org.eclipse.** company.@0
rule ch.qos.** company.@0
rule com.fasterxml.** company.@0
rule biz.paluch.** company.@0

我的build.gradle:

代码语言:javascript
复制
/* Gradle version: 3.0 */
apply plugin: 'java'
apply plugin: 'jacoco'

group='com.company'
version=0.1

repositories {
    jcenter()
}

dependencies {
    compile group: 'org.javassist', name: 'javassist', version: '3.20.0-GA'
    compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
    compile group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.core', version: '3.12.2'
    compile 'biz.paluch.logging:logstash-gelf:1.11.0'
    testCompile 'junit:junit:4.12'
}

// Create jar with manifest as described
jar {
    manifest {
        attributes ('Premain-Class': 'com.company.instrumentation.Agent',
                'Can-Redefine-Classes': true,
                'Can-Retransform-Classes': true,
                'Can-Set-Native-Method-Prefix': true,
                'Main-Class': 'com.company.Main')
    }
}

//create a single Jar with all dependencies
task fatJar(type: Jar) {
    manifest.from jar.manifest
    classifier = 'all'
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    } {
            // to prevent duplicate files in jar
            exclude "META-INF/*"
            exclude '.api_description'
            exclude '.options'
            exclude '*.html'
            exclude 'plugin.properties'
            exclude 'plugin.xml'
            exclude 'about_files/*'
    }
    with jar
}

我试图检查jarjar是否使用java -jar jarjar-1.4.jar find class myApp.jar正确地检测了类之间的依赖关系。

对于代码中的所有类,我都会得到这样的错误:Error reading com/company/Main.class: null

是什么导致了这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-18 13:36:16

导致此错误的原因是JarJar使用了不支持JDK 8字节码的ASM4.0。这可以通过构建这个被修改为使用ASM5.0的JarJar叉来解决。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43304586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档