Maven的安装配置详解
作者:~李疆 时间:2023-11-24 08:52:05
下载maven
解压路径:
打开环境变量:右键此电脑-属性-高级系统设置-高级-环境变量
添加以下系统变量:
测试:win+r输入cmd
输入mvn -v,如果出现下面这些信息,就说明maven安装成功,环境变量设置成功。
修改本地仓库路径:
阿里云仓库的配置:
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
新建工作空间,在eclipse中进行基础的设置:https://blog.csdn.net/qq_40323256/article/details/90141711
新建Maven工程:
(1)如果不勾选:Create a simple project,如下:
(2)如果勾选:Create a simple project,如下:
然后我们看到有报错,如下:
此时只需要在src-main-webapp下面新建文件夹“WEB-INF”,并在此文件夹下新建web.xml文件即可。或者直接在项目右键【javaEETools】-【generate deployment...】
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>HelloJavaWeb</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>
</web-app>
我们现在看到jre system library的后面是[j2se-1.5],
现在我们把它变为[javase-1.8]:
window-show view-other...
等待编译,大概2分钟
在pom.xml界面中右键:maven-add plugin
但是还不够,还要添加<configuration>标签内容,如下:
即:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
更新一下项目即可,步骤:右键项目-maven-update project...,这时候可以看到不报错了。
然后创建servlet:
引入servlet的包:
在pom.xml界面中,右键-maven-Add dependency
然后在pom.xml中可以看到添加的依赖,如下:
但是这还不够,还要添加:<scope>provided</scope>,如下:
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<version>7.0.47</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.47</version>
</dependency>
</dependencies>
然后再:window-preferences:
项目右键-build path-Configure build path...
运行:runAs-maven build...,
注意:首次运行maven项目时,Goals中输入:clean tomcat7:run
对于非首次运行的maven项目,Goals中最好用这个,出现的bug少:clean tomcat7:redeploy
如果项目有报错,试试更新maven项目再运行:右键项目-【maven】-【update project...】
]
来源:https://blog.csdn.net/qq_40323256/article/details/90140747
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
c# 可选参数、命名参数
如何使用HttpClient发送java对象到服务器
springboot返回图片流的实现示例
java文件操作之java写文件简单示例
Java读写文件创建文件夹多种方法示例详解
Android Jetpack库剖析之LiveData组件篇
java清除html转义字符
详细分析Java中String、StringBuffer、StringBuilder类的性能
c# Thread类的用法详解
Android三种方式实现ProgressBar自定义圆形进度条
详解java中保持compareTo和equals同步
mybatis in查询条件过长的解决方案
![](https://img.aspxhome.com/file/2023/4/70594_0s.png)
jar命令的用法详解
Android Rsa数据加解密的介绍与使用示例
![](https://img.aspxhome.com/file/2023/3/94973_0s.png)
关于C# dynamic装箱问题
java和matlab画多边形闭合折线图示例讲解
![](https://img.aspxhome.com/file/2023/7/94317_0s.jpg)
java获取文件的inode标识符的方法
C语言 OutputDebugString与格式化输出函数OutputDebugPrintf案例详解
![](https://img.aspxhome.com/file/2023/3/105163_0s.jpg)
Java8中LocalDateTime与时间戳timestamp的互相转换
SpringBoot配置Email发送功能实例
![](https://img.aspxhome.com/file/2023/3/61943_0s.jpg)