Maven and Creating Maven Project using Archetype in Secs
Expectations from the article:
- What is the Build tool and different types of build tools?
-What is Maven?
- Where to find Maven dependencies?
- How to create a Maven Project in a few seconds?
Build Tool
It’s an essential tool required for the process of building an Application/Project.
It does the following:
* Generating the Source code
* Generating documentation from the source code
* Compile the source code
* Package the source code into Jar
* Install the Packaged code into the repository
Few types of build tools:
- Maven
- Gradle
- Webpack
- Gulp
- CMake
What is Maven?
- Maven is the most commonly used build tool that helps in project management. The build tool helps in building and documenting the Project.
It is based on Project Object Model and that’s the reason you can also find POM.xml in the root directory of your project.
POM contains all the dependencies and configurations required for your project. When you execute a task, MAVEN will try to search for POM.xml
Maven (mvn) dependencies can be found at: https://mvnrepository.com/
Different approaches to creating mvn project:
- From IDE
- Spring initializr: https://start.spring.io/
- From Command-line (CLI)
How to create a maven project using CLI in secs?
- mvn project can be generated using archetype.
Archetype: It is a templating toolkit
To create a simple mvn project, execute the below command:
mvn archetype:generate \
-DgroupId=com.mycompany \
-DartifactId=my-project \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.4ORmvn archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DgroupId=com.mycompany \
-DartifactId=my-project
Note: These must all be on a single line. This will create a directory called my-project
containing all the project descriptors so that you do need not create any project skeleton.
You can disable the interactive mode by setting it false but it's good to have it.
OR
Use the command mvn archetype:generate
, by doing so it will ask you all other details like groupId, artifactId, version, package etc one by one(there is some default value for some of the fields like Version) which in the above case we did all in one line as part of our command and at the end, it will show you all the value you provided and ask for confirmation.
References:
Best practices
Details about POM
For Quickstart and Troubleshooting
Intention: To make learning Simple. Let me know if you have any feedback or what to know something specific.
HAPPY CODING!!