I am new to gradle and learning now. I am trying to build a runnable jar using gradle(My builded jar should be run from command prompt). I just started with a simple HelloWorld project with a dependency and try to build it using gradle. I am not using maven. So I added the dependency jar to the lib folder inside project folder. Below are the details.
Gradle Version: 3.1 Eclipse Version: Neon
HelloWorld.java
package com.padhu.test;
import org.joda.time.LocalTime;
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
LocalTime currentTime = new LocalTime();
System.out.println("The current local time is: " + currentTime);
System.out.println("Hello World");
}
}
build_path_snap
build.gradle file:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'com.padhu.test.HelloWorld'
repositories {
flatDir {
dirs 'lib'
}
}
dependencies {
compile files(fileTree(dir: 'lib', includes: ['*.jar']))
}
jar {
manifest {
attributes(
'Main-Class': 'com.padhu.test.HelloWorld'
)
}
}
I can successfully execute gradle build in my cmd and jar file is getting generated. But inside jar file, I can see only HelloWorld folder structure, but couldnt see the dependency files. So I am not able to run the jar from command prompt since I am getting NoClassDefFoundError: org/joda/time/LocalTime…
I tried fixing the issue myself by searching and reading blogs…but I am not able to run the jar successfully.
Kindly help me.