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ù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Mybatis?sqlMapConfig.xml中的mappers標簽使用
這篇文章主要介紹了Mybatis?sqlMapConfig.xml中的mappers標簽使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教。2022-01-01詳解SpringMVC實現(xiàn)圖片上傳以及該注意的小細節(jié)
本篇文章主要介紹了詳解SpringMVC實現(xiàn)圖片上傳以及該注意的小細節(jié),具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-02-02SpringCloud?Alibaba環(huán)境集成之nacos詳解
Spring?Cloud?Alibaba提供了越來越完善的各類微服務治理組件,比如分布式服務配置與注冊中心nacos,服務限流、熔斷組件sentinel等,本篇先來介紹SpringCloud?Alibaba環(huán)境集成之nacos詳解,需要的朋友可以參考下2023-03-03SSH框架網(wǎng)上商城項目第17戰(zhàn)之購物車基本功能
這篇文章主要為大家詳細介紹了SSH框架網(wǎng)上商城項目第17戰(zhàn)之購物車基本功能的實現(xiàn)過程,感興趣的小伙伴們可以參考一下2016-06-06深入剖析java中String、StringBuffer、StringBuilder的區(qū)別
下面小編就為大家?guī)硪黄钊肫饰鰆ava中String、StringBuffer、StringBuilder的區(qū)別。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05