Today, I came across one new term Maven. I am going to share what I learnt about it.
Introduction to Maven:
If we are to create a project say a web application, there are lots of jars need to be added, example for Hibernate, Spring, Servlet, Driver etc. Sometimes in future, we wish to replace our jar with latest version. It becomes very difficult to search for particular jar in the pool of so many jar files.
Second problem arises when in our project some dependencies are to be added and some of the dependencies, say, are dependent on few more dependencies. It that case also, it becomes very difficult to manage all such dependencies and adding them in such a way such that there is no mismatch of versions.
Maven solves all such problem and much more also. It is an automated build tool. Maven is also used for project management. It generates reports for the project on its own.
Integration of Maven with eclipse:
-
- Open Eclipse. Do, New-> Maven Project. Make your Java EE perspective is on.
- A window will open as shown below. Just click Next.

- In the Next screen, select catalog as ‘Internal’ and select the archetype which you require. I am creating a web application, so I have selected maven-archetype-webapp. Click Next.Archetype is project structure basically. In the introduction, I mentioned that maven is used as project management tool. Here, there comes its application. Maven will automatically create the project structure which you specify as archetype; like for web application, it will create src, webapp, WEB_INF, web.xml etc.

- In next screen, fill the Group Id and Artifact Id. Group Id is reverse of domain name. Artifact Id is name of output of project(jar, war, ear etc. For Web Application, output is war file). Click Finish.

- Now, project is created. Expand your project structure and expand the target folder. You will see a file named pom.xml.POM(Project Object Model), is an XML file containing details of the project like project name, version, package type, dependencies, Maven plugins, etc.Switch to its source view, you will see something like this.

- You must have noticed an error in your project in project structure. Go to src -> main -> webapp. Open the error containing file, index.jsp(in most cases). When you will hover the cursor on red cross in file(at first line), it says-“The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path”.This error comes because Servlet dependency is not included in the project. Just add the dependency in pom.xml. Then press Ctrl+S.

You will see error has gone. Write your Web application code and enjoy with maven 🙂
If you want to go ahead with Maven and learn more about it, go for this video tutorial.
One thought on “Maven”