在发音上,不同人发音可能不同
Apache软件基金会(非盈利的组织,把一些开源软件维护管理起来)
maven是Apache的一个开源项目,是一个优秀的项目构建的(管理)工具.
maven可以管理项目中的jar,以及jar之间的依赖关系.(A.jar中要用到B.jar)
maven可以完成项目编译,测试,打包等功能
pom.xml 里面可以配置相关信息,指导Maven如何工作.
坐标:jar包在仓库中的唯一位置,Apache将全部jar包在服务器端统一进行管理
每个jar包都有一个唯一地址,开发者只需要在项目中配置需要使用的jar的地址(坐标)
Maven就会自动
仓库:官方存储jar文件的仓库
中央仓库:官方提供的,访问速度慢
中央仓库镜像:在全球各地对中央层库进行备份(例如阿里云),国内访问速度快
本地仓库:在程序员电脑上的仓库,第一次使用时从官方下载到本地,以后直接从本地直接引用即可
Maven的搭建
1.先在官网上下载Maven(https://maven.apache.org/)将其存储到自己指定的目录
2.下载完找到指定目录中的bin文件,将其地址复制,在系统的环境变量中添加以搭建环境变量,再通过终端输入mvn -verison来检验是否搭建成功
3.在指定目录的conf文件中的setting文件中
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
将-->修改至| Default: ${user.home}/.m2/repository后
修改后:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository -->
<localRepository>/path/to/local/repo</localRepository>
然后配置阿里云Maven镜像仓库
找到
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
</mirrors>
在</mirrors>前加
<mirror>
<id>aliMaven</id>
<name>aliyun Maven</name>
<url>http://Maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
修改后:
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>aliMaven</id>
<name>aliyun Maven</name>
<url>http://Maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
4.在文件资源管理器中新建一个文件夹
5.打开Java语言开发的集成环境(IDEA),在File中找到new projects setting中的setting for new project配置Maven,找到Build,Execution,...下的Build Tools下的Maven,将User settings file更改到指定目录的conf的修改后的settings文件,将Local repository更改为刚才新建的文件夹,记得点击Apply
6.在IDEA中创建一个Maven项目,会自动下载保存到新建的文件夹下
Maven中的命令
clean 清除之前的编译
compile编译
package打包
打包
就是将本地开发的项目进行打包(jar包,里面都是编译后的Class文件),最终把jar
<properties> <maven.compiler.source>1.8</maven.compiler.source> <!-- 设置 Java 源代码兼容性 --> <maven.compiler.target>1.8</maven.compiler.target> <!-- 设置编译的目标 JVM 版本 --> </properties>
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-5</version> <configuration> <descriptorRefs> <!--给 jar 包起的别名--> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <!--添加项目中主类--> <mainClass>com.ffyc.chatrom.client.frame.Run</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>