zoukankan      html  css  js  c++  java
  • 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>
            

      

  • 相关阅读:
    单例模式
    C++继承-重载-多态-虚函数
    c++仿函数 functor
    常用排序算法实现与效率比较
    树的中序非递归遍历
    二叉树递归遍历
    队列的顺序存储框架
    栈的链式存储框架
    栈的顺序存储构架
    函数指针和回调函数
  • 原文地址:https://www.cnblogs.com/jiangtao1218/p/9966139.html
Copyright © 2011-2022 走看看