Maven的安裝配置詳解
下載maven

解壓路徑:

打開(kāi)環(huán)境變量:右鍵此電腦-屬性-高級(jí)系統(tǒng)設(shè)置-高級(jí)-環(huán)境變量
添加以下系統(tǒng)變量:


測(cè)試:win+r輸入cmd
輸入mvn -v,如果出現(xiàn)下面這些信息,就說(shuō)明maven安裝成功,環(huán)境變量設(shè)置成功。

修改本地倉(cāng)庫(kù)路徑:

阿里云倉(cāng)庫(kù)的配置:

<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
新建工作空間,在eclipse中進(jìn)行基礎(chǔ)的設(shè)置:https://blog.csdn.net/qq_40323256/article/details/90141711


新建Maven工程:
(1)如果不勾選:Create a simple project,如下:




(2)如果勾選:Create a simple project,如下:


然后我們看到有報(bào)錯(cuò),如下:

此時(shí)只需要在src-main-webapp下面新建文件夾“WEB-INF”,并在此文件夾下新建web.xml文件即可?;蛘咧苯釉陧?xiàng)目右鍵【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>
我們現(xiàn)在看到j(luò)re system library的后面是[j2se-1.5],

現(xiàn)在我們把它變?yōu)閇javase-1.8]:
window-show view-other...



等待編譯,大概2分鐘

在pom.xml界面中右鍵:maven-add plugin


但是還不夠,還要添加<configuration>標(biāo)簽內(nèi)容,如下:

即:
<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>
更新一下項(xiàng)目即可,步驟:右鍵項(xiàng)目-maven-update project...,這時(shí)候可以看到不報(bào)錯(cuò)了。
然后創(chuàng)建servlet:


引入servlet的包:
在pom.xml界面中,右鍵-maven-Add dependency



然后在pom.xml中可以看到添加的依賴(lài),如下:

但是這還不夠,還要添加:<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:



項(xiàng)目右鍵-build path-Configure build path...

運(yùn)行:runAs-maven build...,
注意:首次運(yùn)行maven項(xiàng)目時(shí),Goals中輸入:clean tomcat7:run
對(duì)于非首次運(yùn)行的maven項(xiàng)目,Goals中最好用這個(gè),出現(xiàn)的bug少:clean tomcat7:redeploy
如果項(xiàng)目有報(bào)錯(cuò),試試更新maven項(xiàng)目再運(yùn)行:右鍵項(xiàng)目-【maven】-【update project...】
]


到此這篇關(guān)于Maven的安裝配置詳解的文章就介紹到這了,更多相關(guān)Maven 安裝配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringCloud Eureka Provider及Consumer的實(shí)現(xiàn)
這篇文章主要介紹了SpringCloud Eureka 提供者及調(diào)用者的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10
Spring mvc AJAX技術(shù)實(shí)現(xiàn)原理解析
這篇文章主要介紹了Spring mvc AJAX技術(shù)實(shí)現(xiàn)原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
Java通過(guò) Socket 實(shí)現(xiàn) TCP服務(wù)端
這篇文章主要介紹了Java通過(guò) Socket 實(shí)現(xiàn) TCP服務(wù)端的相關(guān)資料,需要的朋友可以參考下2017-05-05
Java使用SFTP上傳文件到服務(wù)器的簡(jiǎn)單使用
這篇文章主要介紹了Java使用SFTP上傳文件到服務(wù)器的簡(jiǎn)單使用,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-02-02
Java獲取Prometheus監(jiān)控?cái)?shù)據(jù)的方法實(shí)現(xiàn)
本文主要介紹了Java獲取Prometheus監(jiān)控?cái)?shù)據(jù)的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-12-12
Java使用BigDecimal公式精確計(jì)算及精度丟失問(wèn)題
在工作中經(jīng)常會(huì)遇到數(shù)值精度問(wèn)題,比如說(shuō)使用float或者double的時(shí)候,可能會(huì)有精度丟失問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于Java使用BigDecimal公式精確計(jì)算及精度丟失問(wèn)題的相關(guān)資料,需要的朋友可以參考下2023-01-01
springboot+vue前后端分離項(xiàng)目中使用jwt實(shí)現(xiàn)登錄認(rèn)證
本文介紹了如何在SpringBoot+Vue前后端分離的項(xiàng)目中使用JWT實(shí)現(xiàn)登錄認(rèn)證,內(nèi)容包括后端的響應(yīng)工具類(lèi)、JWT工具類(lèi)、登錄用戶(hù)實(shí)體類(lèi)、登錄接口、測(cè)試接口、過(guò)濾器、啟動(dòng)類(lèi)以及前端的登錄頁(yè)面實(shí)現(xiàn),感興趣的可以了解一下2024-10-10

