maven基础

maven基础

1. 编译Java文件

mvn compile

2. 执行main方法

mvn exec:java -Dexec.mainClass="com.msn.Hello"

mvn exec命令可以执行项目中的main函数 :

首先需要编译java工程:mvn compile 不存在参数的情况下:mvn exec:java -Dexec.mainClass="com..classname" 存在参数:mvn exec:java -Dexec.mainClass=".Main" -Dexec.args="arg0 arg1 arg2" 指定运行时库:mvn exec:java -Dexec.mainClass="***.Main" -Dexec.classpathScope=runtime

3. maven常用命令

命令用途
mvn -v/-version显示版本信息
mvn clean请i项目产生的临时文件,一般是模块下target目录
mvn compile编译源代码,一般编译模块小的src/mian/java目录
mvn package项目打包工具,在模块的targe目录生成jar或war等文件
mvn test测试命令
mvn install将打包的jar/war文件复制到本地仓库,供其他模块使用
mvn deploy 
mvn site 
mvn jar:jar打jar包
mvn source:jar或mvn source:jar-no-fork源码打包
mvn tomcat7:run,mvn jetty:run 

3.1 命令参数

  • -D传入属性参数

    例如:

    打包的时候跳过单元测试:

    mvn package -Dmaven.test.skip=true

    部署的时候跳过单元测试:

    mvn deploy -Dmaven.test.skip=true

  • -P使用指定的Profile配置

    如在pom.xml中设置开发、测试、生产环境

    例如:

    mvn package -Pdev -Dmaven.test.skip=true

    mvn package -Pproduct -Dmaven.test.skip=true

4. 启动web项目

  • jetty:run -Djetty.port=8899

  • tomcat7:run

5. 打包

1. pom.xml中添加Profile配置

<!-- 打包环境配置 -->
  <profiles>
    <profile>
      <id>dev</id>
      <properties>
        <env>dev</env>
      </properties>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
    </profile>
​
    <profile>
      <id>product</id>
      <properties>
        <env>product</env>
      </properties>
    </profile>
  </profiles>

2. pom.xml设置资源文件配置

<!-- 项目资源配置文件放在build中 -->
    <resources>
      <resource>
        <directory>src/main/resources/${env}</directory>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
          <include>**/*.properties</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>

3. 执行打包操作

clean compile package -Pdev -Dmaven.test.skip=true

clean compile package -Pproduct -Dmaven.test.skip=true

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值