安装本地的maven参考:https://blog.csdn.net/flower_CSDN/article/details/79946008
我的第一个maven项目版本管理程序
1.点击window =>preferencs => maven => installtions添加自己下好的本地的maven(关于怎么安装maven建议百度)
2.点击add添加本地的maven目录
3.选择自己的maven
4.点击User Settings,找到自己安装settings.xml 我的在E:\apache-maven-3.6.1\conf\settings.xml
6.新建一个maven项目,没有这个选项可以在other里面找
7.记住打勾
8.点击next
9.编写项目名称
10.选择Packgaing
11.创建完了项目pom.xml会报错,我们点击这个就行了
12.添加jar包
13.这里我使用的是struts2注解开发
添加完了以后会出现这些代码
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.it</groupId>
<artifactId>maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.24</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.24</version>
</dependency>
</dependencies>
</project>
14.编写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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>maven</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>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
15.编写Java代码
action类
package com.it.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
@ParentPackage(value = "struts-default")
@Namespace(value="/")
public class Hello_Maven extends ActionSupport {
@Action(value="hello",results= {
@Result(location="/jsp/hello_maven.jsp")
})
public String hello() {
System.out.println("action过来了");
return SUCCESS;
}
}
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/hello.action">hello-maven</a>
</body>
</html>
hello_maven.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
我的第一个使用maven创建的程序
</body>
</html>
16.添加和启动项目,在浏览器输入地址
17.跳转成功
整体的项目结构
总结:配置maven一定要细心。由于我是自学maven的,所以在开始安装maven的过程中有各种困难。有句老话说得好,万事开头难,耐心的把问题一个个的解决了,后面也就顺了。加油吧!