smali

воскресенье, 9 марта 2014 г.

Setup of Dynamic Web Project using Maven


Setup of Dynamic Web Project using Maven
http://fruzenshtein.com/setup-of-dynamic-web-project-using-maven/
Create a Dynamic Web Project with Maven in Eclipse Juno
https://www.mhus.de/wp/create-a-dynamic-web-project-with-maven-in-eclipse-juno/

Today I want to talk about Maven. It’s very powerful instrument and if you know how to use it you will make minimum effort to achieve maximum result. In general Maven helps you to manage a project including library dependencies, building process and etc… But in the article I’m going to show you one of the ways how to create a Dynamic Web Project using Maven (in Eclipse IDE).

Pre-requirements:
  • Eclipse IDE for Java EE Developers
  • M2E plugin for Eclipse
  • Maven
1. File > New (Alt+Shift+N) > Dynamic Web Project
  • Input some name for the project in the “Project name” field (e.g. mavenDWP);
  • Select some “Target runtime” (I use Apache Tomcat 7.0);
  • Click on the “Next” button;
  • Create the following directory structure (please pay attention to the directory structure. It’s an important detail in the creation of Dynamic Web Project):
Maven-Dynamic-Web-Project-directory-structure




  • Click on the “Next” button;
  • Select the “Generate web.xml deployment descriptor” check-box;
  • Click on the “Finish” button.
Structure-of-maven-web-project
2. Right click on the project > Configure > Convert to Maven Project
  • Select “Packaging” as a WAR;
  • Click on the “Finish” button;
  • After that, pom.xml will appear in the project’s structure;
  • Move all stuff from the WebContent folder to src/main/webapp;
  • WebContent folder can be deleted after that.
3. Open the project’s root folder in the file system
  • Execute the following command: mvn eclipse:eclipse -Dwtpversion=2.0
  • This command will generate a configuration for eclipse (.classpath, .project, etc.).
  • Expand src > main and make a right click on the webapp folder: Build Path > Use as Source Folder (This point is actual only if src/main/webapp disappeared from the source folders).
Here is the final view of the Dynamic Web Project configured with Maven:
Final-view-of-maven-web-project


02. 
03.import java.io.IOException;
04. 
05.import javax.servlet.ServletException;
06.import javax.servlet.http.HttpServlet;
07.import javax.servlet.http.HttpServletRequest;
08.import javax.servlet.http.HttpServletResponse;
09. 
10.public class Test04Servlet extends HttpServlet {
11. 
12.@Override
13.protected void doGet(HttpServletRequest req, HttpServletResponse resp)
14.throws ServletException, IOException {
15. 
16.resp.setContentType("text/html");
17.resp.getWriter().print("Hello");
18. 
19.}
20. 
21.}
And extend the file web.xml located in ‘Deployment-Resources/webapp/WEB-INF’ and append the following tags:
    <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>de.mhus.test.Test04Servlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>




Комментариев нет:

Отправить комментарий