博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

how to build a runable jar

Posted on 2012-06-20 17:31  钟悍  阅读(303)  评论(0编辑  收藏  举报


 

<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.karl.learn</groupId>
    <artifactId>RR-Loadgen</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>FirstMavenProject</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <archive>
                        <manifest>
                            <mainClass>com.karl.test.tools.Loadgen</mainClass>
                        </manifest>
                    </archive>

                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>
</project>

 

 

execute this jar file:

java -jar jarname.jar 

 

use : 'mvn clean assembly:assembly'  to compile.