<!-- 引入依赖 -->
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- JDK配置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Tomcat配置 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
我又来更新我遇到的新的问题了,可能在写项目中大家也存在这些问题。
首先我们先来看项目
1、新建一个Maven项目,命名为Maven01
点击File-->New-->Maven Project
到这里的时候记得点击箭头指向的小框框,因为这样是建立一个小型项目,它的意思是跳过原型选择
Group id 就是项目包 这个你随便写
Artifact id 就是项目名,这里我们命名为Maven-Struts
Packaging 生成的是war包,默认是jar,这里改一下,点击完成
name 对这个项目的描述
新建好的项目报错,八成是没有web.xml,我们来生成一下。
右键点击选择Java EE Tools--->Generate Deployment Descriptor Stub 点击之后,我们点击一下就可以生成web.xml啦。
我们打开项目,你会看到目录最下面的pom.xml文件
那么我们来了解一下,什么是pom.xml
pom作为项目对象模型。通过xml表示maven项目,使用pom.xml来实现。主要描述了项目:包括配置文件;开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的url,项目的依赖性,以及其他所有的项目相关因素。这里就不详细介绍了,略过
1、配置pom.xml文件
首先引入依赖,其次配置JDK和Tomcat 代码如下
依赖可以在Maven Repository 中找到 官网地址:https://mvnrepository.com/
<!-- 引入依赖 -->
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- JDK配置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Tomcat配置 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
2、新建一个JSP页面(index.isp)
首先把charset=ISO-8859-1改为中文编码 charset=UTF-8
代码如下:
<%@ 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>
山有木兮木有枝,心悦君兮君不知。
</body>
</html>
配置完毕,我们了编译下
右键单击项目,选择Run As--->5Maven clean
编译完之后,控制台输出日志,当我们看到输出BUILD SUCCESS时,代表我们编译成功。
然后运行,步骤同编译类似,右键单击项目,选择Run As--->4Maven build
输入密钥:tomcat7:run 点击Appay-->Run
当我们看到控制台输出一下内容时,就代表了我们运行成功,并没有报错
复制路径,打开浏览器,输入浏览
以上就是一个简单的Maven了。应该是不会报错的。
下一篇写Maven 搭建Struts2项目,挥爪子。