导出的可运行jar不包含使用Java 11的eclipse 2018-12中的依赖jar。如何解决此问题?

时间:2019-02-21 05:58:07

标签: java eclipse build.gradle

我的byild.gradle文件

能够使用JAVA 8导出jar。当我配置为JAVA 11时,导出的jar不包含外部jars

//应用java库插件添加对Java库的支持     应用插件:“ java-library”

// In this section you declare where to find the dependencies of your project
repositories {
    jcenter()
}

configurations 
    { 
        all*.exclude group: 'org.slf4j', module: 'slf4j-log4j12' //by both name and group
    }

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:21.0'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'

    compile group: 'com.microsoft', name: 'sqljdbc4', version: '3.0'
    compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'
    compile group: 'com.ibatis', name: 'ibatis2-common', version: '2.1.7.597'
    compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
    compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
    compile group: 'org.json', name: 'json', version: '20171018'

    compile group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13'
    compile group: 'com.itextpdf.tool', name: 'xmlworker', version: '5.5.13'  
    testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.2'
}

1 个答案:

答案 0 :(得分:0)

将此行添加到您的build.gradle

jar { manifest {attributes "Main-Class": "your main class" } from {configurations.compile.collect { it.isDirectory()? it : zipTree(it) } }

然后进行清理/构建, 在\ build \ libs文件夹中创建的jar是您可运行的jar