• Maven 梳理-手动创建Maven项目(非web),使用Maven编译、测试、打包、安装、引用


    1. 创建空目录
      1.   F:jtDevelopmaventestmyapp
    2. 创建pom.xml文件
      1.  
        <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">
          <modelVersion>4.0.0</modelVersion>
          <groupId>com.mycompany.app</groupId>
          <artifactId>myapp</artifactId>
          <packaging>jar</packaging>
          <version>1.0-SNAPSHOT</version>
          <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
        
          </dependencies>
        </project>
    3. 创建目录
      1.   F:jtDevelopmaventestmyappsrcmainjava
    4. 编写java文件
      1.   F:jtDevelopmaventestmyappsrcmainjavaCal.java
      2. public class Cal{
            private String name;
            public void setName(String name){
                this.name=name;
            }
            public String getName(){
                return "Hello "+this.name;
            }
            public static void main(String[] args){
                System.out.println("Hello Maven");
            }
        }
    5. 使用Maven编译
      1.   
        F:jtDevelopmaventestmyapp>cd F:jtDevelopmaventestmyapp
        
        F:jtDevelopmaventestmyapp>mvn compile

        [INFO] BUILD SUCCESS
    6. 编写测试类文件
      1.   F:jtDevelopmaventestmyappsrc estjavaCalTest.java
      2. import org.junit.BeforeClass;
        import org.junit.Test;
        
        import junit.framework.TestCase;
        
        public class CalTest {
            static Cal c=null;
            @BeforeClass
            public static void init(){
                c=new Cal();
                c.setName("jt");
            }
            @Test
            public void testGetName(){
                String v=c.getName();
                TestCase.assertEquals("Hello jt", v);
            }
        }
    7. 运行测试
      1.   
         T E S T S
        -------------------------------------------------------
        Running CalTest
        Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.062 sec
        
        Results :
        
        Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
        
        [INFO] ----------------------------------------------------------------------
        [INFO] BUILD SUCCESS
        [INFO] ----------------------------------------------------------------------
        [INFO] Total time:  2.124 s
        [INFO] Finished at: 2018-11-15T21:50:52+08:00
        [INFO] ----------------------------------------------------------------------
        
        F:jtDevelopmaventestmyapp>mvn test
    8. 打包
      1.   
        执行"mvn package"命令
      2. 多了一个文件  F:jtDevelopmaventestmyapp argetmyapp-1.0-SNAPSHOT.jar
    9. 安装
      1.   执行
        执行"mvn install"命令
      2. 多了两个文件
        1.   F:jtDevelopmaventest epositoryscommycompanyappmyapp1.0-SNAPSHOTmyapp-1.0-SNAPSHOT.jar
        2. F:jtDevelopmaventestmyapp argetmyapp-1.0-SNAPSHOT.jar
    10. 在其他项目中使用本项目的jar包
      1.   新建maven项目
      2. 编辑pom.xml
        1. <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">
            <modelVersion>4.0.0</modelVersion>
            <groupId>com.mycompany.app</groupId>
            <artifactId>myapp2</artifactId>
            <packaging>jar</packaging>
            <version>1.0-SNAPSHOT</version>
            <dependencies>
              <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.12</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>com.mycompany.app</groupId>
                  <artifactId>myapp1</artifactId>
                  <version>1.0-SNAPSHOT</version>
                  <scope>test</scope>
              </dependency>
          
            </dependencies>
          </project>
            

      

  • 相关阅读:
    Silverlight+WCF 实战网络象棋最终篇之房间装修WCF端(二)
    win7下如何添加虚拟网卡(转)
    Python天天美味(12) 条件判断的缩写(转)
    MENUITEMINFO结构的翻译(转)
    C语言写Python extension实践(转)
    Python天天美味(15) Python正则表达式操作指南(re使用)(转)
    Python Import机制备忘模块搜索路径(sys.path)、嵌套Import、package Import(转)
    python单例模式(转)
    Python 操作剪贴板(转)
    Base64加密原理(转)
  • 原文地址:https://www.cnblogs.com/jiangtao1218/p/9966139.html
Copyright © 2020-2023  润新知