本文介绍了如何在Gradle中导出可执行的jar文件,并且该jar文件可以运行,因为它包含了参考库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



build.gradle


$如何在Gradle中导出可执行文件jar,并且该jar文件可以运行,因为它包含引用库。 b $ b

  apply plugin:'java'

manifest.mainAttributes(Main-Class:com.botwave.analysis.LogAnalyzer)

存储库{
mavenCentral()
}

依赖项{
编译(
'commons-codec:commons-codec: 1.6',
'commons-logging:commons-logging:1.1.1',
'org.apache.httpcomponents:httpclient:4.2.1',
'org.apache.httpcomponents: httpclient:4.2.1',
'org.apache.httpcomponents:httpcore:4.2.1',
'org.apache.httpcomponents:httpmime:4.2.1',
'ch。 qos.logback:logback-classic:1.0.6',
'ch.qos.logback:logback-core:1.0.6',
'org.slf4j:slf4j-api:1.6.0' ,
'junit:junit:4. +'

}



我运行后:gradle构建



它创建build文件夹,我在build / libs / XXX.jar中运行jar:



java -jar build / libs / XXX.jar



这里有一个执行说:

 线程main中的异常java.lang.NoClassDefFoundError:ch / qos / logback / core / joran / spi / JoranException 

如何使用参考库运行它?

解决方案

a href =http://gradle.org/docs/current/userguide/application_plugin.html =noreferrer> Gradle应用程序插件


how to export a executable jar in gradle, and this jar can run as it include reference libraries.

build.gradle

apply plugin: 'java'

manifest.mainAttributes("Main-Class" : "com.botwave.analysis.LogAnalyzer")

repositories {
    mavenCentral()
}

dependencies {
    compile (
        'commons-codec:commons-codec:1.6',
        'commons-logging:commons-logging:1.1.1',
        'org.apache.httpcomponents:httpclient:4.2.1',
        'org.apache.httpcomponents:httpclient:4.2.1',
        'org.apache.httpcomponents:httpcore:4.2.1',
        'org.apache.httpcomponents:httpmime:4.2.1',
        'ch.qos.logback:logback-classic:1.0.6',
        'ch.qos.logback:logback-core:1.0.6',
        'org.slf4j:slf4j-api:1.6.0',
        'junit:junit:4.+'
    )
}

after i run : gradle build

it create the build folder, and i run the jar in build/libs/XXX.jar:

java -jar build/libs/XXX.jar

here is a execution says :

Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException

how can i run it with the reference libraries?

解决方案

You can achieve it with Gradle application plugin

这篇关于如何在Gradle中导出可执行的jar文件,并且该jar文件可以运行,因为它包含了参考库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 06:09