Goto the folder where the new project is created and execute above command.Code language: HTML, XML (xml)mvn eclipse:eclipse -Dwtpversion=1.5
C:\Workspace\Test\MavenWeb>mvn eclipse:eclipse -Dwtpversion=1.5 [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. [INFO] ------------------------------------------------------------------------ [INFO] Building Unnamed - MavenWeb:MavenWeb:war:0.0.1-SNAPSHOT [INFO] task-segment: [eclipse:eclipse] [INFO] ------------------------------------------------------------------------ [INFO] Preparing eclipse:eclipse [INFO] No goals needed for project - skipping [INFO] [eclipse:eclipse] [INFO] Adding support for WTP version 1.5. [INFO] Using Eclipse Workspace: C:\Workspace\Test [INFO] no substring wtp server match. [INFO] Using as WTP server : Apache Tomcat v5.5 [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Not writing settings - defaults suffice [INFO] Wrote Eclipse project for "MavenWeb" to C:\Workspace\Test\MavenWeb. [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Wed Jul 28 13:55:09 CEST 2010 [INFO] Final Memory: 7M/30M [INFO] ------------------------------------------------------------------------That’s it. We just created Dynamic Web Project from Maven project. Now refresh the project in Eclipse.
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>MavenWeb</groupId>
<artifactId>MavenWeb</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<description></description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</project>
Code language: HTML, XML (xml)
Also create a servlet file HelloWorldServlet.java. We will add this servlet in net.viralpatel.maven package. File: /src/main/java/net/viralpatel/maven/HelloWorldServlet.java package net.viralpatel.maven;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1031422249396784970L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.print("Hello World from Servlet");
out.flush();
out.close();
}
}
Code language: Java (java)
Once the servlet is created, let us configure this in web.xml. Note that in our maven project no web.xml is present. We will create one at /src/main/webapp/WEB-INF/ location. File: /src/main/webapp/WEB-INF/web.xml <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>HelloWorldServlet</display-name>
<welcome-file-list>
<welcome-file>hello-world</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>
net.viralpatel.maven.HelloWorldServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello-world</url-pattern>
</servlet-mapping>
</web-app>
Code language: HTML, XML (xml)
Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…
Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…
Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…
1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…
GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…
1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…
View Comments
All you had to do is to install "Maven Integration for WTP".
Some time ago I created a similar post on how to create dynamic web project with Eclipse 3.5. See http://blog.goyello.com/2010/06/15/how-to-create-java-web-application-with-eclipse-wtp-and-m2eclipse/. The project can be downloaded here: http://blog.goyello.com/wp-content/uploads/2010/06/wtp-m2eclipse-demo.zip
Recently I found out that with Eclipse 3.6 and m2eclipse you could use webapp-jee5 archetype that works perfectly with WTP and Eclipse 3.6. Of course, Maven integration for WTP is required (available via m2eclipse extras update site)
thanks for sharing ;)
Thanks for sharing :) Really amazing !
how can I configure Eclipse 3.2, Maven 2.0, and M2Eclipse Plugin together? sorry im just beginner. thanks.
and how to integrate it to spring mvc3 framework?
For integrating maven + eclipse you need to download and install the m2eclipse plugin from your Eclipse IDE (help -> update software, or eclipse marketplace). AND you HAVE TO download the Maven from the link provided in the beginning of this tutorial - Required software - 3. Maven 2.0 or above. Once you have it, scroll down the maven download page and check installation instructions for you system. That should all work together.
thanks for your tutorial, but I want to notice that the version of hibernate-entitymanager is not well as far to lanch example, so to resolve this, I replace this :
org.hibernate
hibernate-entitymanager
3.3.2.ga
by this :
org.hibernate
hibernate-annotations
3.3.1.GA
Hi,
First of all i want to thank you I've learned a lot.
Can you please help me with this
Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [hibernate.cfg.xml] cannot be resolved to URL because it does not exist
Thank you my friend for writing this tutorial! Very very helpful.