首页 > 代码库 > maven项目用assembly打包可执行jar包

maven项目用assembly打包可执行jar包

该方法只可打包非spring项目的可执行jar包,spring项目可参考:http://www.cnblogs.com/guazi/p/6789679.html

1.添加maven插件:

<!-- Maven Assembly Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4.1</version>
                    <configuration>
                        <!-- get all project dependencies -->
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <!-- MainClass in mainfest make a executable jar -->
                        <archive>
                          <manifest>
                            <mainClass>com.jobscrawler.crawlers.ShhCrawler</mainClass>
                          </manifest>
                        </archive>
     
                    </configuration>
                    <executions>
                      <execution>
                        <id>make-assembly</id>
                                            <!-- bind to the packaging phase -->
                        <phase>package</phase> 
                        <goals>
                            <goal>single</goal>
                        </goals>
                      </execution>
                    </executions>
                </plugin>

2.mvn clean(清理下项目)

3.maven update project

4.命令后执行命令mvn assembly:assembly -Dmaven.test.skip

  进入target目录会看到这两个jar包:

    jobscrawler-1.0-SNAPSHOT-jar-with-dependencies.jar
    jobscrawler-1.0-SNAPSHOT.jar

5.执行 java -jar jobscrawler-1.0-SNAPSHOT-jar-with-dependencies.jar

 

如果这个不管用,可以参考http://www.cnblogs.com/liqiu/p/3816068.html

http://www.cnblogs.com/liqiu/p/4508848.html

---恢复内容结束---

maven项目用assembly打包可执行jar包