How to Create Build Java Project including all Dependencies Using Maven? maven-resources, maven-dependency & maven-jar Plugin

Are you working on enterprise level Java Project? Using Maven POM.xml file to keep all dependancies up-to date? In your project do you have src folder, resources folder, lib folder, etc? Well, what if you want to deploy this project to 3rd party client? Any other standalone hardware?

Well, there is a simple way to build and create your Java Project’s executable with Maven Plugins. Take a look at below sample Java Project.

Build Create Executable using Maven Plugins How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Plugin

Let’s get started and let me explain all parts of project.

  1. CrunchifyMavenBuildPlugins is a Maven Project. If you have Java project and wanted to convert it into Maven project then follow this tutorial.
  2. We do have two folders. src and resources.
  3. Inside resources folder we do have a folder called Scripts which contains one executable shell script file.
  4. CrunchifyMain.java is a main starting point which has main(String args[]) method inside.
  5. pom.xml file in which we will add Maven Plugins which will build executable .jar project with all included dependancies.

Step1: Open your pom.xml file and add below under <build>. Note: I’ve added 3 plugins below below.

  1. maven-resources-plugin: The Resources Plugin handles the copying of project resources to the output directory. The main resources are the resources associated to the main source code.
  2. maven-dependency-plugin: The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.
  3. maven-jar-plugin: This plugin provides the capability to build and sign jars.

Please update directory location, filename and path as per your need below.

Step2: Right Click on Project -> Run As -> Maven Build

Maven Build in Eclipse How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Plugin

Step 3: Provide argument “clean install

Clean Install Maven Build in Eclipse How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Plugin

Step 4: You should see result something like this.

Console Result How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Plugin

Step 5: Now check target folder to check you have everything under that.

Complete Executable Java Project build by Maven Plugins How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Plugin

Step 6: Now just run your project with below command $bash> java -jar Crunchify.jar

Do let me know if you have any problem building project. Enjoy and Happy Coding.

If you enjoyed this post, help spread knowledge & subscribe to Crunchify's RSS feed.
twitter How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Pluginfacebook How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Plugingoogle How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Pluginpinterest How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Plugintumblr How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Pluginbuffer How to Create Build Java Project including all Dependencies Using Maven? maven resources, maven dependency & maven jar Plugin