eclipse创建maven项目

编程

1、修改工作空间默认字符集为UTF-8

Eclipse菜单 -> Window -> Preferences -> General ->Workspace

2、安装JST Server

--默认安装的eclipse Preferences菜单下没有server选项

3、安装wtp工具集

--默认安装的eclipse Preferences菜单下没有Project Facets选项

4、修改JSP默认编辑器

--高亮显示jsp文件内容

eclipse创建maven 普通java项目

1、先创建maven父项目(可选)

File -> New -> Project

2、创建maven module子项目

右键parent-project选择Maven选项,创建新的Maven Module Project

创建测试类

eclipse创建maven java web项目

右键parent-project选择Maven选项,创建新的Maven Module Project

勾选后Next

选择war然后Finish

发现没有web.xml

项目(javaweb-project)右键 ->Properties ->Project Facets

点击Apply and Close,web.xml生成了

创建servlet测试java web项目

1、添加项目到server

2、配置pom.xml文件,添加maven依赖

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>

<groupId>com.dingyibo.test</groupId>

<artifactId>parent-project</artifactId>

<version>0.0.1-SNAPSHOT</version>

</parent>

<groupId>com.dingyibo.test.javaweb</groupId>

<artifactId>javaweb-project</artifactId>

<packaging>war</packaging>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

</properties>

<dependencies>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

<version>3.0.1</version>

<scope>provided</scope>

</dependency>

</dependencies>

</project>

3、新建index.jsp文件

<%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>首页</title>

</head>

<body>

hi,javaweb

</body>

</html>

4、创建MavenServlet测试类

package com.dingyibo.test.javaweb.servlet;

import java.io.IOException;

public class MavenServlet extends javax.servlet.http.HttpServlet {

protected void doPost(javax.servlet.http.HttpServletRequest request,

javax.servlet.http.HttpServletResponse response)

throws javax.servlet.ServletException, IOException {

response.getWriter().write("hello maven");

}

protected void doGet(javax.servlet.http.HttpServletRequest request,

javax.servlet.http.HttpServletResponse response)

throws javax.servlet.ServletException, IOException {

doPost(request,response);

}

}

5、配置web.xml添加servlet配置

<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

<display-name>javaweb-project</display-name>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

<welcome-file>default.html</welcome-file>

<welcome-file>default.htm</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

<servlet>

<servlet-name>MavenServlet</servlet-name>

<servlet-class>com.dingyibo.test.javaweb.servlet.MavenServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>MavenServlet</servlet-name>

<url-pattern>/maven-java-web</url-pattern>

</servlet-mapping>

</web-app>

6、运行测试

浏览器访问:localhost:8080

浏览器访问:http://localhost:8080/javaweb-project/maven-java-web

 

以上是 eclipse创建maven项目 的全部内容, 来源链接: utcz.com/z/512986.html

回到顶部