How to create a web project using Maven in Eclipse
ADVERTISEMENT
Table of Contents
- Introduction
- 1. Step-1
- 2. Step-2
- 4. Step-4
- 5. Step-5
- 6. Step-6
- 7. Step-7
- 8. Step-8
- Summary
- Next Steps
Introduction
In this tutorial, we provide a step-by-step guide on how to create a web project using Maven in Eclipse.
Prerequisites:
- Eclipse IDE (Mars release)
- Java 1.8
- Apache tomcat 8
1. Step-1
Open eclipse, then select File -> New -> Maven Project.
2. Step-2
In the next screen, select the workspace of the project and keep the other options as default then click “Next”:
3. Step-3
In the following screen, select “maven-archetype-webapp” then click “Next”:
4. Step-4
In the final screen, fill the mandatory fields as the following:
- “Group Id”: denotes a unique “dot” separated group name, which is used by external projects that link to yours, this field is normally set as the company name.
- “Artifact Id”: denotes the name of the web project.
- The main package of the project is the concatenation of “Group Id” + “Artifact Id”
Click “Finish”.
5. Step-5
Eclipse now generates a dynamic web project called “SimpleWebProject”, in case you face this error inside index.jsp:
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path index.jsp
then just add the following dependency to pom.xml:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
6. Step-6
In order to compile your project with Java 8, add the following property to pom.xml:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
then right click project -> Maven -> Update Project
7. Step-7
Here we go, the structure of the generated project looks like the following:
8. Step-8
Finally deploy the web application on Tomcat, if you haven’t setup Tomcat in your eclipse, then follow this guide.
After the deployment, you would be able to access index.jsp through the following url:
localhost:<PORT_NUMBER>/SimpleWebProject/index.jsp
That’s it.
Summary
In this tutorial, we provide a step-by-step guide on how to create a web project using Maven in Eclipse.
Next Steps
If you're interested in learning more about the basics of Java, coding, and software development, check out our Coding Essentials Guidebook for Developers, where we cover the essential languages, concepts, and tools that you'll need to become a professional developer.
Thanks and happy coding! We hope you enjoyed this article. If you have any questions or comments, feel free to reach out to jacob@initialcommit.io.
Final Notes
Recommended product: Coding Essentials Guidebook for Developers