Maven的安裝配置詳解
下載maven

解壓路徑:

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


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

修改本地倉庫路徑:

阿里云倉庫的配置:

<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文件即可?;蛘咧苯釉陧椖坑益I【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)在看到jre system library的后面是[j2se-1.5],

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



等待編譯,大概2分鐘

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


但是還不夠,還要添加<configuration>標簽內(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>
更新一下項目即可,步驟:右鍵項目-maven-update project...,這時候可以看到不報錯了。
然后創(chuàng)建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中最好用這個,出現(xiàn)的bug少:clean tomcat7:redeploy
如果項目有報錯,試試更新maven項目再運行:右鍵項目-【maven】-【update project...】
]


到此這篇關于Maven的安裝配置詳解的文章就介紹到這了,更多相關Maven 安裝配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
SpringCloud Eureka Provider及Consumer的實現(xiàn)
這篇文章主要介紹了SpringCloud Eureka 提供者及調(diào)用者的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-10-10
Java獲取Prometheus監(jiān)控數(shù)據(jù)的方法實現(xiàn)
本文主要介紹了Java獲取Prometheus監(jiān)控數(shù)據(jù)的方法實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-12-12
springboot+vue前后端分離項目中使用jwt實現(xiàn)登錄認證
本文介紹了如何在SpringBoot+Vue前后端分離的項目中使用JWT實現(xiàn)登錄認證,內(nèi)容包括后端的響應工具類、JWT工具類、登錄用戶實體類、登錄接口、測試接口、過濾器、啟動類以及前端的登錄頁面實現(xiàn),感興趣的可以了解一下2024-10-10

