lunes, 25 de abril de 2016

Como crear un proyecto java incluyendo todas las dependencias usando Maven? ‘maven-resources’, ‘maven-dependency’ & ‘maven-jar’ Plugins

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
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.

Step-1

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.

Step-2

Right Click on Project -> Run As -> Maven Build
Maven Build in Eclipse

Step-3

Provide argument “clean install
Clean Install - Maven Build in Eclipse

Step-4

You should see result something like this.
Console Result

Step-5

Now check out the folder folder /target/Crunchify to check everything under that.
Complete-Executable-Java-Project-build-by-Maven-Plugins-Crunchify-Tips

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.
Have a suggestion or anything to add to this article? Chime in and share as a comment OR post it in forum.

Fuente:

No hay comentarios:

Publicar un comentario