maven

Maven是一个跨平台的项目管理工具,主要用于基于java平台的项目构建,依赖管理。


1.下载,配置bin目录到path中,mvn -v  测试是否配置成功

2.F:\apache-maven-3.5.0-bin\apache-maven-3.5.0\conf\setting.xml里面配置本地仓库的地址   <localRepository>F:\mavenresp</localRepository>

Cmd运行mvn命令,先找用户setting.xml(用户配置)(建议删除了),再去找maven安装目录 中的conf下的setting.xml(全局配置,一定要配置本地仓库)。


3.maven项目的约定的目录结构

src/main/java存放项目的java文件
src/main/resources存放项目的资源文件,如spring,hibernate的配置文件
src/test/java  存放所有的测试的java文件
src/test/resources存放测试用的资源文件
target  项目输出位置
pom.xml  文件 

4.mvn命令和生命周期

 

清理mvn clean  target    下的内容清空
编译mvn compile         编译后,target中出现class文件,但是不管test里面的内容
测试mvn test           只要进行测试,清理和编译可以自动执行了。 
报告 
打包mvn package    执行后 target中出现jar包
部署mvn install           把工程放到仓库里面  

target/classes存放编译后的类

target/test-classes存放编译后的测试类

target/surefire-reports存放测试报告



5.pom.xml

<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.0</modelVersion>

  <groupId>com.itheima11.maven</groupId>
  <artifactId>Hello</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Hello</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.9</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

project:表示一个工程

modelVersion:为版本号

坐标:
groupId:定义当前maven项目属于哪个项目
artifactId:定义实际项目中的某一个模块
version:定义当前项目的当前版本
packaging:定义当前项目的打包方式

继承:打包方式必须是pom,只继承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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.itheima11.maven</groupId>
  <artifactId>Base</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>


  <parent>
  	 <groupId>com.itheima11.maven</groupId>
  	 <artifactId>Base</artifactId>
  	 <version>0.0.1-SNAPSHOT</version>
  </parent>

6.仓库:本地--》企业私服(nuex)--》中央仓库

setting.xml中配置私服:



如果不想连接私服,可以直接连接互联网。只需要把连接私服的所有的路径去掉即可。


<?xml version="1.0" encoding="UTF-8"?>    
<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">    

    <pluginGroups></pluginGroups>
    <proxies></proxies>

    <servers>
        <server>
            <id>nexus-releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>  
            <id>nexus-snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>

    <mirrors>
        <mirror>     
            <id>nexus-releases</id>     
            <mirrorOf>*</mirrorOf>     
            <url>http://192.168.1.8:8081/nexus/content/groups/public</url>     
        </mirror>    
        <mirror>     
            <id>nexus-snapshots</id>     
            <mirrorOf>*</mirrorOf>     
            <url>http://192.168.1.8:8081/nexus/content/groups/public-snapshots</url>     
        </mirror>     
    </mirrors>     

    <profiles>    
        <profile>    
            <id>nexus</id>    
            <repositories>    
                <repository>    
                    <id>nexus-releases</id>    
                    <url>http://nexus-releases</url>    
                    <releases><enabled>true</enabled></releases>    
                   <snapshots><enabled>true</enabled></snapshots>    
                </repository>    
                <repository>    
                    <id>nexus-snapshots</id>    
                    <url>http://nexus-snapshots</url>    
                    <releases><enabled>true</enabled></releases>    
                    <snapshots><enabled>true</enabled></snapshots>    
                </repository>    
            </repositories>    
            <pluginRepositories>    
                <pluginRepository>    
                    <id>nexus-releases</id>    
                    <url>http://nexus-releases</url>    
                    <releases><enabled>true</enabled></releases>    
                    <snapshots><enabled>true</enabled></snapshots>    
                </pluginRepository>    
                <pluginRepository>    
                    <id>nexus-snapshots</id>    
                    <url>http://nexus-snapshots</url>    
                    <releases><enabled>true</enabled></releases>    
                    <snapshots><enabled>true</enabled></snapshots>    
                </pluginRepository>    
            </pluginRepositories>    
        </profile>    
    </profiles>    
     
    <activeProfiles>    
        <activeProfile>nexus</activeProfile>    
    </activeProfiles>    
      
</settings>    








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值