maven 笔记 安装和集成到idea

maven是一个构建项目的工具。用maven构建的项目结构十分清晰。

依赖管理:maven可以对项目的第三方jar进行统一的管理,通过maven定义的jar包的坐标,自动从maven仓库中去下载到工程中。

项目构建:maven提供了一套对项目声明周期管理的标准。开发人员和测试人员统一使用maven对项目进行构建。项目生命周期管理:编译、测试、打包、部署、运行。

maven对项目可以分模块构建,提高开发效率。


maven中央仓库

http://www.sonatype.org/nexus/
http://mvnrepository.com/ (本人推荐仓库)
http://repo1.maven.org/maven2

本地仓库(相当于缓存)

工程第一次添加依赖的时候会从远程仓库中下载jar包,将jar包缓存到本地仓库中。等第二次用到相同的jar包时,会直接去本地仓库中查找,查找不到才会去远程仓库下载。

私服仓库,公司内部架设的仓库,对外不公开。


maven坐标定义的元素如下:

groupId:项目组织的唯一标识符,实际对应的java的包的结构。一般写公司的名称

artifactId:项目的名称

version:项目的当前版本


安装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>
     -->
    <!--<mirror>
      <id>maven-default-http-blocker</id>
      <mirrorOf>external:http:*</mirrorOf>
      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>-->
	 <!--<mirror>
		<id>aliyunmaven</id>
		<mirrorOf>*</mirrorOf>
		<name>阿里云公共仓库</name>
		<url>https://maven.aliyun.com/repository/public</url>
	</mirror>-->
	<mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <url>http://repo1.maven.org/maven2/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>
        <mirror>
            <id>ibiblio</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
        </mirror>
        <mirror>
            <id>jboss-public-repository-group</id>
            <mirrorOf>central</mirrorOf>
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
        </mirror>
        <mirror>
            <id>google-maven-central</id>
            <name>Google Maven Central</name>
            <url>https://maven-central.storage.googleapis.com
            </url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <!-- 中央仓库在中国的镜像 -->
        <mirror>
            <id>maven.net.cn</id>
            <name>oneof the central mirrors in china</name>
            <url>http://maven.net.cn/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
		</mirror>
  </mirrors>

修改maven创建项目默认的java版本

<profiles>
  <profile>  
  <id>jdk-1.8</id>  
   <activation>  
     <activeByDefault>true</activeByDefault>  
     <jdk>1.8</jdk>  
   </activation>  
	<properties>  
		<maven.compiler.source>1.8</maven.compiler.source>  
		<maven.compiler.target>1.8</maven.compiler.target>  
		<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
		<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
	</properties>
	</profile>
    
  </profiles>

在idea中集成maven

设置所有项目

 

第一次创建项目的时候一定要联网,因为有可能需要下载依赖

-DarchetypeCatalog=internal

加快Maven构建项目工程 -DarchetypeCatalog=internal_Clearlast .的博客-CSDN博客_darchetype


使用maven创建javase工程

 new model 

使用骨架方式创建javase项目

 

使用骨架方式创建javaweb项目

 不使用骨架创建javaweb工程

直接下一步

 创建好后,在pom.xml文件里首先指定打包方式为war

 在main下面新建webapp,在webapp下创建WEB_INF

 然后WEB_INF下面的web.xml


介绍一种通过插件的方式将普通java工程转换成javaweb项目

JavaToWeb 简介 转换 java 的模块工程为 web 模块工程; 生成的 web.xml 文件支持 Servlet 2.5。

然后右键对应的项目

 

 

posted @ 2022-07-19 00:41  在线电影制作人  阅读(6)  评论(0)    收藏  举报  来源