How to create a runnable JAR file with Gradle
This post will show you how we can compile and package a simple Java Project using Gradle into a runnable JAR file
The default project layout of a Java project with Gradle is following (just like Maven):
So now make a new folder where you would like the project to start:
Let’s create the project layout by using the following commands:
As you can see from above the project layout looks just like a Maven project.
Creating the Main Class
Let’s create the main class for this project and make it display “Hello World” cd into src/main/java and create the package layout.
We have the project layout created and also the package layout so now it’s time to create the Main Class
and insert the following lines:
Creating the Gradle Build File..
The next step is to create the Gralde Build file, Go back to the root of the project. cd ../../.. And create the build file
Now add the following lines:
Building the project and creating the JAR To build the project and to create the JAR you need to run the following command
Now to run the JAR file you enter the following command
If you have any questions or comments please email me at email@example.com