Creating standalone Java project using Maven Archetype

Maven archetypes make it easy to start projects with a standard/consistent code structure. Instead of repeating these steps in every blog that needs starting a project, this blog will be used to show common steps used to start new projects using Maven Archetypes. This post focuses on standalone apps.

Create Application structure

The name of artifactId to be changed as per the actual name of the project to be created

Create Folders

Create folders src/main/resources, src/test/resources.

Update pom.xml

Add properties to maintain versions and other variables at one place :

Dependencies to use the version numbers from properties:

Plugin to specify java version as desired:

Import Maven project into Eclipse

Note: This step can be repeated when ever eclipse is not recognizing the changes in pom.xml etc and refresh the project in Eclipse

Open Eclipse with C:\tvi\Software\workspace_mars as workspace directory. File –> Import –> Existing Maven Projects. Root Directory C:\tvi\Software\workspace_mars\standalone-utils. Select standalone-utils’s pom.xml

Test

Open App.java (test java code created by Maven) and change its package location to com.techvalueinsight.apps. Right-Click on the file and Run As –> Java Application. It prints the customary ‘Hello World!’

image

Leave a Reply

Your email address will not be published. Required fields are marked *