Advantages of using Maven project.
1. All the required jar are added.
2. It removes dependancy of one jar on another.
3. It helps to create project file structure.
4. It helps to build, publish and deploy the project.
How to setup Maven.
1. Download the latest binary zip archive from https://maven.apache.org/download.cgi.
2. Extract it.
3. Add following environment variables
M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.3.3
M2=%M2_HOME%\bin
MAVEN_OPTS=-Xms256m -Xmx512m
Add %M2%; to PATH environment variable
4. Now open the command prompt and run the following command.
>mvn --version
If path is set ok, then you will see the output.
Creating a project.
1. create a directory
>mkdir myapp
2. mvn archetype:generate
Arctype is project structure
1. All the required jar are added.
2. It removes dependancy of one jar on another.
3. It helps to create project file structure.
4. It helps to build, publish and deploy the project.
How to setup Maven.
1. Download the latest binary zip archive from https://maven.apache.org/download.cgi.
2. Extract it.
3. Add following environment variables
M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.3.3
M2=%M2_HOME%\bin
MAVEN_OPTS=-Xms256m -Xmx512m
Add %M2%; to PATH environment variable
4. Now open the command prompt and run the following command.
>mvn --version
If path is set ok, then you will see the output.
Creating a project.
1. create a directory
>mkdir myapp
2. mvn archetype:generate
Arctype is project structure
Group id is package name
artifact id is Application name.
Version is version number
Package is what kind of packaging would be. like jar, war or ear.
When you select any structure it creates that file structure and pom.xml. In the pom.xml, dependancy jars are mentioned. Following command build project.
artifact id is Application name.
Version is version number
Package is what kind of packaging would be. like jar, war or ear.
When you select any structure it creates that file structure and pom.xml. In the pom.xml, dependancy jars are mentioned. Following command build project.
3.
mvn package
mvn test
mvn compile
mvn build
mvn install
mvn clean
Suppose you added import org.sl4j.*; in your code.
Now if you compile the application (mvn compile), it will fail.
So you have to go to http://mvnrepository.com/ and search for slf4j. Click on the api link. Click on the version you like. Then copy the dependancy snippet and paste in pom.xml of the project under dependencies element. Then compile will be successful.
To add maven plugin in Eclipse:
help->Install->Work with (--All Available Sites--). Type maven. Select General Purpose Tools with m2e Maven Integration for Eclipse . Then install it.
You can do the same with Maven eclipse plugin. Create a Maven project. Then you can choose archetype. You can compile, build and everything.
No comments:
Post a Comment