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
    

      

  • 相关阅读:
    Hdu4547CD操作离线lca
    1036: [ZJOI2008]树的统计Count树链剖分
    light1348Aladdin and the Return Journey树链剖分
    Problem 2082 过路费树链剖分
    2243: [SDOI2011]染色树链剖分
    Poj3237Tree 树链剖分
    Poj2763Housewife Wind树链剖分
    Hdu5087Revenge of LIS II简单dp
    Hdu5088Revenge of Nim II高斯消元
    Bootstrap入门学习笔记(只记录了效果)
  • 原文地址:https://www.cnblogs.com/jifeng/p/4786522.html
Copyright © 2011-2022 走看看