maven 1: install assembly:assembly, 打包所有依赖

 

让编译出来的jar包,包含所有的依赖项,这样就可以独立运行了

 

In the section called “Running the Simple Weather Program”, we executed the Simple Weather application using the Maven Exec plugin. While the Maven Exec plugin executed the program and produced some output, you shouldn't look to Maven as an execution container for your applications. If you are distributing this command-line application to others, you will probably want to distribute a JAR or an archive as a ZIP or TAR'd GZIP file. The following section outlines a process for using a predefined assembly descriptor in the Maven Assembly plugin to produce a distributable JAR file which contains the project's bytecode and all of the dependencies.

The Maven Assembly plugin is a plugin you can use to create arbitrary distributions for your applications. You can use the Maven Assembly plugin to assemble the output of your project in any format you desire by defining a custom assembly descriptor. In a later chapter we will show you how to create a custom assembly descriptor which produces a more complex archive for the Simple Weather application. In this chapter, we're going to use the predefined jar-with-dependencies format. To configure the Maven Assembly Plugin, we need to add the following plugin configuration to our existing build configuration in the pom.xml.

Configuring the Maven Assembly Descriptor

 

ContractedBlock.gif ExpandedBlockStart.gif Configuring the Maven Assembly Descriptor
 
   
< project >
[...]
< build >
< plugins >
< plugin >
< artifactId > maven-assembly-plugin </ artifactId >
< configuration >
< descriptorRefs >
< descriptorRef > jar-with-dependencies </ descriptorRef >
</ descriptorRefs >
</ configuration >
</ plugin >
</ plugins >
</ build >
[...]
</ project >

 

Once you've added this configuration, you can build the assembly by running mvn assembly:assembly.

$ cd target$ java -cp simple-weather-1.0-jar-with-dependencies.jar com.sonatype.maven.weather.Main 100020    INFO  YahooRetriever  - Retrieving Weather Data221  INFO  YahooParser  - Creating XML Reader399  INFO  YahooParser  - Parsing XML Response474  INFO  WeatherFormatter  - Formatting Weather Data********************************* Current Weather Conditions for:  New York, NY, US   Temperature: 44   Condition: Fair    Humidity: 40  Wind Chill: 40*********************************

The jar-with-dependencies format creates a single JAR file which includes all of the bytecode from the simple-weather project and the unpacked bytecode from all of the dependencies. This somewhat unconventional format produces a 9 MiB JAR file containing approximately 5290 classes, but it does provide for an easy distribution format for applications you've developed with Maven. Later in this book, we'll show you how to create a custom assembly descriptor to produce a more standard distribution.

 

转载于:https://www.cnblogs.com/forward/archive/2010/02/03/1662772.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven-assembly-plugin是一个用于打包的插件,可以将项目中的多个模块合并成一个可执行的JAR包或者WAR包。然而,有时候我们可能需要对已经打包好的JAR或者WAR包进行进一步的处理或者外部打包。以下是关于maven-assembly-plugin外部打包的解答。 首先,我们需要确保已经正确配置了maven-assembly-plugin,并且在项目的pom.xml文件中已经定义好了自定义的assembly描述文件(assembly.xml)。 在进行外部打包之前,我们需要先将项目进行构建和打包。在项目根目录下通过命令行输入"mvn clean install"命令来构建项目,并且将项目打包成JAR或者WAR文件。 接下来,在项目根目录下创建一个新的文件夹(例如,external_package),用于存放外部打包的文件。 然后,可以通过以下命令来进行外部打包: mvn assembly:assembly -Ddescriptor=assembly.xml -DoutputDirectory=/path/to/external_package 在上面的命令中,-Ddescriptor参数用于指定assembly描述文件所在的路径以及文件名称,-DoutputDirectory参数用于指定外部打包文件存放的路径。 执行完上述命令后,maven-assembly-plugin会根据assembly.xml文件的定义,在指定的路径下生成外部打包文件。 通过以上步骤,我们就可以实现maven-assembly-plugin的外部打包功能。需要注意的是,我们在进行外部打包之前,需要先正确配置和打包项目,并且确保已经定义了正确的assembly描述文件。 外部打包可以用于将项目的可执行文件(如JAR或者WAR文件)与其它资源(如配置文件或者依赖库)合并打包成一个单独的压缩文件,方便部署和分发。它可以帮助我们将项目打包成一个易于使用和发布的形式,简化部署流程,提高开发效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值