zoukankan      html  css  js  c++  java
  • maven学习笔记(定制普通Java一个项目)

    创建一个新项目:

    mvn archetype:generate -DgroupId=cn.net.comsys.ut4.simpleweather -DartifactId=simple-weather -DpackageName=cn.net.comsys.ut4.simpleweather -Dversion=1.0
    

    generate目标文档:Generate project in batch mode

    为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>cn.net.comsys.ut4.simpleweather</groupId>
      <artifactId>simple-weather</artifactId>
      <version>1.0</version>
      <packaging>jar</packaging>
    
      <name>simple-weather</name>
      <url>http://WWW.COMSYS.NET.CN</url>
      
      <licenses>
    	<license>
    		<name>Apache 2</name>
    		<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    		<distribution>repo</distribution>
    		<comments>A business-friendly OSS license</comments>
    	</license>
    </licenses>
    
    <organization>
    	<name>COMSYS</name>
    	<url>http://WWW.COMSYS.NET.CN</url>
    </organization>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </project>
    

      如licenses、organization等

    Maven Exec 插件

    install成jar后可以通过exec执行main方法

    mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main
    

    Exec 插件让我们能够在不往 classpath 载入适当的依赖的情况下,运行这个程序

    查看exec插件目标以及参数帮助:

    mvn help:describe -Dplugin=exec -Dfull
    

    查看项目依赖:

     mvn dependency:resolve
    
    mvn dependency:tree
    

    执行单元测试:

     mvn test
    

      忽略测试失败:<testFailureIgnore>true</testFailureIgnore>

    <project>
    	[...]
    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-surefire-plugin</artifactId>
    				<configuration>
    					<testFailureIgnore>true</testFailureIgnore>
    				</configuration>
    			</plugin>
    		</plugins>
    	</build>
    	[...]
    </project>
    

      也可以通过命令行参数设置

     mvn test -Dmaven.test.failure.ignore=true
    

      

    跳过单元测试:

    mvn install -Dmaven.test.skip=true
    

      

    构建一个打包好的命令行应用程序

    想pom.xml增加一下内容

    <project>
    	[...]
    	<build>
    		<plugins>
    			<plugin>
    				<artifactId>maven-assembly-plugin</artifactId>
    				<configuration>
    					<descriptorRefs>
    						<descriptorRef>jar-with-dependencies</descriptorRef>
    					</descriptorRefs>
    				</configuration>
    			</plugin>
    		</plugins>
    	</build>
    	[...]
    </project>
    

      运行以下命令进行装配:

    mvn install assembly:assembly
    

      

  • 相关阅读:
    qt运行时连接signal和slot
    linux使用usb转串口调试ARM开发板
    qwt自定义时间标尺TimeScale
    关于mysql 导入大型数据问题的解决(转载,出处以忘)
    JavaScript replace(RegExp, Function)详解
    有关高度和宽度的对象
    前自增和后自增(chrome js 为了保险,还没测过其它的)
    JavaScript效率PK——统计特定字符在字符串中出现的次数
    getStyle函数
    解决CHM文件在WIN7下崩溃和自动生成CHW文件的问题
  • 原文地址:https://www.cnblogs.com/jifeng/p/4786522.html
Copyright © 2011-2022 走看看