Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 598
jychan Avatar asked Feb 01 '13 04:02

jychan


People also ask

How can I create an executable jar with dependencies using Gradle?

Right click the module > Open module settings > Artifacts > + > JAR > from modules with dependencies. Set the main class.

How do I make a jar file executable into a jar?

Right click on your Java Project and select Export. Select Java -> Runnable JAR file -> Next. Select the Destination folder where you would like to save it and click Finish.

How do I export a jar from an external library?

You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.


1 Answers

You can achieve it with Gradle application plugin

like image 117
erdi Avatar answered Oct 23 '22 20:10

erdi