簡體   English   中英

導出的可運行 jar 不包含來自 eclipse 2018-12 和 java 11 的依賴 jar。我們如何解決這個問題?

[英]exported runnable jar doesn't contain dependency jars from eclipse 2018-12 with java 11. How do we solve this?

我的 byild.gradle 文件

能夠使用 JAVA 8 導出 jar。當我配置為 JAVA 11 時,導出的 jar 不包含外部 jar

// 應用 java-library 插件來添加對 Java 庫的支持 apply plugin: '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'
}

將以下幾行添加到您的 build.gradle 中

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

然后進行清理/構建,在 \\build\\libs 文件夾中創建的 jar 是您的可運行 jar

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM