1.下载
2.安装
maven压缩包解压到一个没有中文,空格或其他特殊字符的文件夹内即可使用。
3.配置环境变量
1.右键此电脑->属性->高级系统设置->环境变量
2.新建系统变量MAVEN_HOME
3.编辑系统变量Path,添加变量值%MAVEN_HOME%\bin
4.验证安装是否成功,win+R运行cmd,输入mvn -v,如图所示则配置成功
4.配置本地仓库
1.在maven的安装目录下创建一个repository文件夹用作本地仓库(一般习惯将仓库地址和maven安装目录放置在一起)。
2.修改本地仓库地址
(1)在Maven安装目录conf目录下找到settings.xml配置文件打开
(2)找到
标签节点并将其改为本地仓库地址
5.配置私服
(1)在Maven安装目录conf目录下找到settings.xml配置文件打开
(2)找到
标签节点并将其改为如下:
将原有注释
//阿里云<mirror> <id>aliyunmavenid> <mirrorOf>*mirrorO> <name>阿里云公共仓库name> <url>https://maven.aliyun.com/repository/publicurl>mirror>## 或//网易<mirror> <id>nexus-163id> <mirrorOf>*mirrorOf> <name>Nexus 163name> <url>http://mirrors.163.com/maven/repository/maven-public/url>mirror>## 或//腾讯云<mirror> <id>nexus-tencentyunid> <mirrorOf>*mirrorOf> <name>Nexus tencentyunname> <url>http://mirrors.cloud.tencent.com/nexus/repository/maven-public/url>mirror>
6.项目结构
没有的 java
或 resources
、或 webapp
要添加进去
7.IDEA配置
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0GG400qK-1675758562809)(null)]
本地获取,添加 -DarchetypeCatalog=internal
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-USnCWraM-1675758552834)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207110348941.png)]
8.pom文件配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> <parent> <artifactId>xxxartifactId> <groupId>xxxgroupId> <version>xxxversion> <relativePath>xxxrelativePath> parent> <modelVersion> 4.0.0 modelVersion> <groupId>xxxgroupId> <artifactId>xxxartifactId> <packaging> jar packaging> <version> 1.0-SNAPSHOT version> <name> xxx-maven name> <url> http://maven.apache.org url> <description> A maven project to study maven. description> <prerequisites> <maven>maven> prerequisites> <issueManagement> <system> jira system> <url> http://jira.baidu.com/banseon url> issueManagement> <ciManagement> <system>system> <url>url> <notifiers> <notifier> <type>type> <sendOnError>sendOnError> <sendOnFailure>sendOnFailure> <sendOnSuccess>sendOnSuccess> <sendOnWarning>sendOnWarning> <address>address> <configuration>configuration> notifier> notifiers> ciManagement> <inceptionYear /> <mailingLists> <mailingList> <name> Demo name> <post> banseon@126.com post> <subscribe> banseon@126.com subscribe> <unsubscribe> banseon@126.com unsubscribe> <archive> http:/hi.baidu.com/banseon/demo/dev/ archive> mailingList> mailingLists> <developers> <developer> <id> HELLO WORLD id> <name> banseon name> <email> banseon@126.com email> <url>url> <roles> <role> Project Manager role> <role> Architect role> roles> <organization> demo organization> <organizationUrl> http://hi.baidu.com/xxx organizationUrl> <properties> <dept> No dept> properties> <timezone> -5 timezone> developer> developers> <contributors> <contributor> <name>name> <email>email> <url>url> <organization>organization> <organizationUrl>organizationUrl> <roles> <role> Project Manager role> <role> Architect role> roles> <timezone>timezone> <properties> <dept> No dept> properties> contributor> contributors> <licenses> <license> <name> Apache 2 name> <url> http://www.baidu.com/banseon/LICENSE-2.0.txt url> <distribution> repo distribution> <comments> A business-friendly OSS license comments> license> licenses> <scm> <connection> scm:svn:http://svn.baidu.com/banseon/maven/banseon/banseon-maven2-trunk(dao-trunk) connection> <developerConnection> scm:svn:http://svn.baidu.com/banseon/maven/banseon/dao-trunk developerConnection> <tag>tag> <url> http://svn.baidu.com/banseon url> scm> <organization> <name> demo name> <url> http://www.baidu.com/banseon url> organization> <build> <sourceDirectory>sourceDirectory> <scriptSourceDirectory>scriptSourceDirectory> <testSourceDirectory>testSourceDirectory> <outputDirectory>outputDirectory> <testOutputDirectory>testOutputDirectory> <extensions> <extension> <groupId>groupId> <artifactId>artifactId> <version>version> extension> extensions> <defaultGoal>defaultGoal> <resources> <resource> <targetPath>targetPath> <filtering>filtering> <directory>directory> <excludes> <exclude>exclude> excludes> resource> resources> <testResources> <testResource> <targetPath>targetPath> <filtering>filtering> <directory>directory> <excludes> <exclude>exclude> excludes> testResource> testResources> <directory>directory> <finalName>finalName> <filters>filters> <pluginManagement> <plugins> <plugin> <groupId>groupId> <artifactId>artifactId> <version>version> <extensions>true/falseextensions> <executions> <execution><id>id><phase>phase><goals>goals><inherited>true/falseinherited><configuration>configuration> execution> executions> <dependencies> <dependency> dependency> dependencies> <inherited>true/falseinherited> <configuration>configuration> plugin> plugins> pluginManagement> <plugins> <plugin> <groupId>groupId> <artifactId>artifactId> <version>version> <extensions>true/falseextensions> <executions> <execution> <id>id> <phase>phase> <goals>goals> <inherited>true/falseinherited> <configuration>configuration> execution> executions> <dependencies> <dependency> dependency> dependencies> <inherited>true/falseinherited> <configuration>configuration> plugin> plugins> build> <profiles> <profile> <id>id> <activation> <activeByDefault>true/falseactiveByDefault> <jdk>jdk版本,如:1.7jdk> <os> <name> Windows XP name> <family> Windows family> <arch> x86 arch> <version> 5.1.2600 version> os> <property> <name> mavenVersion name> <value> 2.0.3 value> property> <file> <exists> /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ exists> <missing> /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ missing> file> activation> <build> <defaultGoal /> <resources> <resource> <targetPath>targetPath> <filtering>filtering> <directory>directory> <includes><include>include> includes> <excludes><exclude>exclude> excludes> resource> resources> <testResources> <testResource> <targetPath>targetPath> <filtering>filtering> <directory>directory> <includes><include>include> includes> <excludes><exclude>exclude> excludes> testResource> testResources> <directory>directory> <finalName>finalName> <filters>filters> <pluginManagement> <plugins> <plugin><groupId>groupId><artifactId>artifactId><version>version><extensions>true/falseextensions><executions> <execution> <id>id> <phase>phase> <goals>goals> <inherited>true/falseinherited> <configuration>configuration> execution>executions><dependencies> <dependency> dependency>dependencies><goals>goals><inherited>true/falseinherited><configuration>configuration> plugin> plugins> pluginManagement> <plugins> <plugin> <groupId>groupId> <artifactId>artifactId> <version>version> <extensions>true/falseextensions> <executions><execution> <id>id> <phase>phase> <goals>goals> <inherited>true/falseinherited> <configuration>configuration>execution> executions> <dependencies><dependency>dependency> dependencies> <goals>goals> <inherited>true/falseinherited> <configuration>configuration> plugin> plugins> build> <modules> <module>module> modules> <repositories> <repository> <releases> <enabled><enabled> <updatePolicy>updatePolicy> <checksumPolicy>checksumPolicy> releases> <snapshots> <enabled><enabled> <updatePolicy>updatePolicy> <checksumPolicy>checksumPolicy> snapshots> <id>id> <name>name> <url>url> <layout>layout> repository> repositories> <pluginRepositories> <pluginRepository> <releases> <enabled><enabled> <updatePolicy>updatePolicy> <checksumPolicy>checksumPolicy> releases> <snapshots> <enabled><enabled> <updatePolicy>updatePolicy> <checksumPolicy>checksumPolicy> snapshots> <id>id> <name>name> <url>url> <layout>layout> pluginRepository> pluginRepositories> <dependencies> <dependency> dependency> dependencies> <reports>reports> <reporting>reporting> <dependencyManagement> <dependencies> <dependency> dependency> dependencies> dependencyManagement> <distributionManagement> distributionManagement> <properties /> profile> profiles> <modules> <module>module> modules> <repositories> <repository> <releases> <enabled><enabled> <updatePolicy>updatePolicy> <checksumPolicy>checksumPolicy> releases> <snapshots> <enabled><enabled> <updatePolicy>updatePolicy> <checksumPolicy>checksumPolicy> snapshots> <id> banseon-repository-proxy id> <name> banseon-repository-proxy name> <url> http://192.168.1.169:9999/repository/ url> <layout> default layout> repository> repositories> <pluginRepositories> <pluginRepository> pluginRepository> pluginRepositories> <dependencies> <dependency> <groupId> org.apache.maven groupId> <artifactId> maven-artifact artifactId> <version> 3.8.1 version> <type> jar type> <classifier>classifier> <scope> test scope> <systemPath>systemPath> <exclusions> <exclusion> <artifactId> spring-core artifactId> <groupId> org.springframework groupId> exclusion> exclusions> <optional> true optional> dependency> dependencies> <reports>reports> <reporting> <excludeDefaults /> <outputDirectory /> <plugins> <plugin> <groupId>groupId> <artifactId>artifactId> <version>version> <inherited>true/falseinherited> <configuration>configuration> <reportSets> <reportSet> <id>id> <configuration>configuration> <inherited>true/falseinherited> <reports>reports> reportSet> reportSets> plugin> plugins> reporting> <dependencyManagement> <dependencies> <dependency> dependency> dependencies> dependencyManagement> <distributionManagement> <repository> <uniqueVersion /> <id> banseon-maven2 id> <name> banseon maven2 name> <url> file://${basedir}/target/deploy url> <layout>layout> repository> <snapshotRepository> <uniqueVersion /> <id> banseon-maven2 id> <name> Banseon-maven2 Snapshot Repository name> <url> scp://svn.baidu.com/banseon:/usr/local/maven-snapshot url> <layout>layout> snapshotRepository> <site> <id> banseon-site id> <name> business api website name> <url> scp://svn.baidu.com/banseon:/var/www/localhost/banseon-web url> site> <downloadUrl /> <relocation> <groupId>groupId> <artifactId>artifactId> <version>version> <message>message> relocation> <status>status> distributionManagement> <properties> <name>valuename> properties>project>
//例如<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0modelVersion> <groupId>com.qhgroupId> <artifactId>mavenartifactId> <version>1.0-SNAPSHOTversion> <packaging>warpackaging> <properties> <maven.compiler.source>19maven.compiler.source> <maven.compiler.target>19maven.compiler.target> <project.build.sourceEncoding>UTF-8project.build.sourceEncoding> properties> <dependencies> <dependency> <groupId>junitgroupId> <artifactId>junitartifactId> <version>4.13.2version> <scope>testscope> dependency> dependencies> <build> <plugins> <plugin> <groupId>org.apache.tomcat.mavengroupId> <artifactId>tomcat7-maven-pluginartifactId> <version>2.2version> <configuration> <port>80port> <path>/path> configuration> plugin> plugins> build> project>
来源地址:https://blog.csdn.net/qq_43699122/article/details/128537162