maven使用例
9513 ワード
mvn archetypeを使う:create-DgroupId=comp.jiepu-DartifactId=ap-Dpackage Name=comp.jiepu-Dversion=2.0 mavenプロジェクトを作成する
その後、jarパッケージのMANIFEST.MFファイルを修正し、追加します。
または次の方法を使用します。
mvn install-Dmaven.test.skyp=true
<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>com.jiepu</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<url>http://maven.apache.org</url>
<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>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
mvn assiem blyを使う:assmably生成に依存するjarその後、jarパッケージのMANIFEST.MFファイルを修正し、追加します。
Main-Class: com.jiepu.App
java-jarを使う test-1.0-NAPSHOT-jar-with-dependencies.jarは実行できます。または次の方法を使用します。
<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.jiepu</groupId>
<artifactId>app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass> com.jiepu.app.App</mainClass>
<packageName>com.jiepu.app</packageName>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
<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.jiepu</groupId>
<artifactId>mvn_echo</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>mvn_echo</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!--echo -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Displaying value of pom.xml element :</echo>
<echo>${basedir}</echo>
<echo>${project.basedir}</echo>
<echo>${version}</echo>
<echo>${project.artifactId}</echo>
<echo>${project.build.testSourceDirectory}</echo>
<echo>${project.build.sourceDirectory}</echo>
<echo>${project.build.directory}</echo>
<echo>${project.groupId}</echo>
<echo>${project.version}</echo>
<echo>${project.build.finalName}</echo>
<echo>${settings.localRepository}</echo>
<echo>${user.home}</echo>
<echo>${env.JAVA_HOME}</echo>
<echo>${project.outputDirectory}</echo>
<echo>${project.testOutputDirectory}</echo>
<echo>${env.PATH}</echo>
<echo>${os.name}</echo>
<echo>${os.arch}</echo>
<echo>${os.version}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<!--mvn site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<configuration>
<locales>zh_CN</locales>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!--javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
</plugin>
<!-- xref -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.2</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
<!--checkstyle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.5</version>
</plugin>
<!--pmd -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
<!--cobertura -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</reporting>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
</project>
はテストをスキップします。mvn install-Dmaven.test.skyp=true