In this article, we will create project using maven provided archetypes. These archetypes are simply template for creating various kinds of projects in Java/J2EE
Now, it’s left to developers to choose what type of project to be created from the lists of available archetypes
Note: There are around 1212 templates available with Apache Maven 3.2.1
1. Creating and Exploring Project using Archetypes
There are two ways to create maven based project
- Using Eclipse IDE [provided maven integrated with Eclipse IDE]
- Maven command approach
1.1 Using Eclipse IDE
Note: Make sure, Maven is integrated with Eclipse IDE before proceeding with below steps
Step 1: Open Eclipse –> File Menu –> New –> Others
Step 2: Type “maven” in the wizard –> select “Maven Project” –> Click Next
Note: Provided maven is already integrated with Eclipse IDE, otherwise this option won’t be available
Step 3: Either use default workspace location or else browse through different workspace location
If we check the option “Create a simple project (skip archetype selection)” –> by default maven archetype “maven-archetype-quickstart” will be selected –> which is similar to creating simple java project
Note: If we want to create web based project, then uncheck this option to move to next step and search for maven archetype “maven-archetype-webapp”
Step 4: By default, “maven-archetype-quickstart” will be selected
For simple Java application, select this option –> move to next step
Step 5: Enter groupId, artifactId & version and package details in text boxes –> Click “Finish”
Group Id: in.bench.resources
Artifact Id: SampleJavWebApp
Version: 0.0.1-SNAPSHOT
Package: com.spring.hibernate.application
Note: This combination needs to be unique among various projects in local maven repository
Step 6: A new project will be created in Eclipse IDE with below structure
Note: we need to modify pom.xml and add packages/classes as per business requirements
1.2 Maven command approach
Before proceeding, we have to make sure that maven installed in the system
For our example, we are using Windows 7 Operating Systems and Apache Maven 3.2.1
Step 1: open command prompt –> check whether maven installed using “mvn –version” command
With below output, we made sure that maven is installed and working fine
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T23:07:52+05:30)
Maven home: D:\Downloads\Jars\apache-maven-3.2.1\bin\..
Java version: 1.7.0_06-ea, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_06\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
Step 2: execute “mvn archetype:generate” command
There are around 1212 template available with Maven 3.2.1 version
Choose among these, whichever suits our requirement
Step 3: For Demo purpose, we will create simple java project
So choose 507 and enter below details
A new project will be created at ‘D:\’ drive location
2. Useful Eclipse IDE shortcuts :
- Eclipse IDE – How to show line numbers ?
- Eclipse IDE – How to GO TO any line number directly ?
- Eclipse IDE – How to remove unused imports ?
- Eclipse IDE – How to clean project ?
- Eclipse IDE – How to build Java project automatically ?
- Eclipse IDE – How to comment and un-comment line & block ?
- Eclipse IDE – How to generate constructor using fields ?
- Eclipse IDE – How to generate getters and setters ?
- Eclipse IDE – How to search files ?
- Eclipse IDE – How to locate methods in Java file ?
- Eclipse IDE – How to open editor using CTRL + E ?
- Eclipse IDE – Java compiler compliance level issue
Related Articles:
- Eclipse + Maven – Integration
- Eclipse + Maven – How to import Maven project with pom.xml ?
- Eclipse + Maven – Setting M2_REPO classpath variable in IDE
- Eclipse + Maven – M2_REPO is Non Modifiable
- Eclipse + Maven – Creating and exploring projects using archetypes
- Eclipse + Maven – Converting Web project to Maven project
- Eclipse + Maven – mvn eclipse:eclipse command
- Eclipse + Maven – Plugin execution not covered by lifecycle configuration
- Apache Maven – Introduction
- Apache Maven – Install on Windows 7 OS
- Apache Maven – Settings.xml explanation
- Apache Maven – Proxy setting explanation
- Apache Maven – pom.xml explanation
- Apache Maven – Plugins explanation
- Apache Maven – Changing default Maven repository location in Windows 7 OS
- Apache Maven – Local, Central and Remote Repositories
- Apache Maven – Installing custom library into local repository
- Apache Maven – Transitive dependencies explanation
- Apache Maven – Exclusion of Transitive dependencies
- Apache Maven – Dependency Scopes
- Apache Maven – Skipping unit test using surefire plugin
- Apache Maven – Exclusions and Inclusions of unit test
- Apache Maven – offline execution
- Apache Maven – Co-ordinates explained
References:
- http://maven.apache.org/guides/introduction/introduction-to-archetypes.html
- http://maven-repository.com/archetypes
Happy Coding !!
Happy Learning !!