apache-maven-3.3.9-bin.tar.gz是哪个包

Maven实战(九)——打包的技巧 - 每天进步一点点! - ITeye技术网站
博客分类:
“打包“这个词听起来比较土,比较正式的说法应该是”构建项目软件包“,具体说就是将项目中的各种文件,比如源代码、编译生成的字节码、配置文件、文档,按照规范的格式生成归档,最常见的当然就是JAR包和WAR包了,复杂点的例子是, 它有自定义的格式,方便用户直接解压后就在命令行使用。作为一款”打包工具“,Maven自然有义务帮助用户创建各种各样的包,规范的JAR包和WAR包 自然不再话下,略微复杂的自定义打包格式也必须支持,本文就介绍一些常用的打包案例以及相关的实现方式,除了前面提到的一些包以外,你还能看到如何生成源 码包、Javadoc包、以及从命令行可直接运行的CLI包。
Packaging的含义
任何一个Maven项目都需要定义POM元素packaging(如果不写则默认值为jar)。顾名思义,该元素决定了项目的打包方式。实际的情形 中,如果你不声明该元素,Maven会帮你生成一个JAR包;如果你定义该元素的值为war,那你会得到一个WAR包;如果定义其值为POM(比如是一个 父模块),那什么包都不会生成。除此之外,Maven默认还支持一些其他的流行打包格式,例如ejb3和ear。你不需要了解具体的打包细节,你所需要做 的就是告诉Maven,”我是个什么类型的项目“,这就是约定优于配置的力量。
为了更好的理解Maven的默认打包方式,我们不妨来看看简单的声明背后发生了什么,对一个jar项目执行mvn package操作,会看到如下的输出:
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ git-demo ---
[INFO] Building jar: /home/juven/git_juven/git-demo/target/git-demo-1.2-SNAPSHOT.jar
相比之下,对一个war项目执行mvn package操作,输出是这样的:
[INFO] --- maven-war-plugin:2.1:war (default-war) @ webapp-demo ---
[INFO] Packaging webapp
[INFO] Assembling webapp [webapp-demo] in [/home/juven/git_juven/webapp-demo/target/webapp-demo-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/juven/git_juven/webapp-demo/src/main/webapp]
[INFO] Webapp assembled in [90 msecs]
[INFO] Building war: /home/juven/git_juven/webapp-demo/target/webapp-demo-1.0-SNAPSHOT.war
对应于同样的package生命周期阶段,Maven为jar项目调用了maven-jar-plugin,为war项目调用了maven-war-plugin,换言之,packaging直接影响Maven的构建生命周期。了解这一点非常重要,特别是当你需要自定义打包行为的时候,你就必须知道去配置哪个插件。一个常见的例子就是在打包war项目的时候排除某些web资源文件,这时就应该配置maven-war-plugin如下:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-war-plugin&/artifactId&
&version&2.1.1&/version&
&configuration&
&webResources&
&resource&
&directory&src/main/webapp&/directory&
&excludes&
&exclude&**/*.jpg&/exclude&
&/excludes&
&/resource&
&/webResources&
&/configuration&
源码包和Javadoc包
本专栏的一 文中曾解释过,一个Maven项目只生成一个主构件,当需要生成其他附属构件的时候,就需要用上classifier。源码包和Javadoc包就是附属 构件的极佳例子。它们有着广泛的用途,尤其是源码包,当你使用一个第三方依赖的时候,有时候会希望在IDE中直接进入该依赖的源码查看其实现的细节,如果 该依赖将源码包发布到了Maven仓库,那么像Eclipse就能通过m2eclipse插件解析下载源码包并关联到你的项目中,十分方便。由于生成源码 包是极其常见的需求,因此Maven官方提供了一个插件来帮助用户完成这个任务:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-source-plugin&/artifactId&
&version&2.1.2&/version&
&executions&
&execution&
&id&attach-sources&/id&
&phase&verify&/phase&
&goal&jar-no-fork&/goal&
&/execution&
&/executions&
类似的,生成Javadoc包只需要配置插件如下:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-javadoc-plugin&/artifactId&
&version&2.7&/version&
&executions&
&execution&
&id&attach-javadocs&/id&
&goal&jar&/goal&
&/execution&
&/executions&
为了帮助所有Maven用户更方便的使用Maven中央库中海量的资源,中央仓库的维护者强制要求开源项目提交构件的时候同时提供源码包和Javadoc包。这是个很好的实践,读者也可以尝试在自己所处的公司内部实行,以促进不同项目之间的交流。
可执行CLI包
除了前面提到了常规JAR包、WAR包,源码包和Javadoc包,另一种常被用到的包是在命令行可直接运行的CLI(Command Line)包。默认Maven生成的JAR包只包含了编译生成的.class文件和项目资源文件,而要得到一个可以直接在命令行通过java命令运行的 JAR文件,还要满足两个条件:
JAR包中的/META-INF/MANIFEST.MF元数据文件必须包含Main-Class信息。
项目所有的依赖都必须在Classpath中。
Maven有好几个插件能帮助用户完成上述任务,不过用起来最方便的还是, 它可以让用户配置Main-Class的值,然后在打包的时候将值填入/META-INF/MANIFEST.MF文件。关于项目的依赖,它很聪明地将依 赖JAR文件全部解压后,再将得到的.class文件连同当前项目的.class文件一起合并到最终的CLI包中,这样,在执行CLI JAR文件的时候,所有需要的类就都在Classpath中了。下面是一个配置样例:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-shade-plugin&/artifactId&
&version&1.4&/version&
&executions&
&execution&
&phase&package&/phase&
&goal&shade&/goal&
&configuration&
&transformers&
&transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&
&mainClass&com.juvenxu.mavenbook.HelloWorldCli&/mainClass&
&/transformer&
&/transformers&
&/configuration&
&/execution&
&/executions&
上述例子中的,我的Main-Class是com.juvenxu.mavenbook.HelloWorldCli,构建完成后,对应于一个常规 的hello-world-1.0.jar文件,我还得到了一个hello-world-1.0-cli.jar文件。细心的读者可能已经注意到了,这里 用的是cli这个classifier。最后,我可以通过java -jar hello-world-1.0-cli.jar命令运行程序。
自定义格式包
实际的软件项目常常会有更复杂的打包需求,例如我们可能需要为客户提供一份产品的分发包,这个包不仅仅包含项目的字节码文件,还得包含依赖以及相关脚本文件以方便客户解压后就能运行,此外分发包还得包含一些必要的文档。这时项目的源码目录结构大致是这样的:
src/main/java/
src/main/resources/
src/test/java/
src/test/resources/
src/main/scripts/
src/main/assembly/
README.txt
除了基本的pom.xml和一般Maven目录之外,这里还有一个src/main/scripts/目录,该目录会包含一些脚本文件如 run.sh和run.bat,src/main/assembly/会包含一个assembly.xml,这是打包的描述文件,稍后介绍,最后的 README.txt是份简单的文档。
我们希望最终生成一个zip格式的分发包,它包含如下的一个结构:
README.txt
其中bin/目录包含了可执行脚本run.sh和run.bat,lib/目录包含了项目JAR包和所有依赖JAR,README.txt就是前面提到的文档。
描述清楚需求后,我们就要搬出Maven最强大的打包插件:。 它支持各种打包文件格式,包括zip、tar.gz、tar.bz2等等,通过一个打包描述文件(该例中是src/main /assembly.xml),它能够帮助用户选择具体打包哪些文件集合、依赖、模块、和甚至本地仓库文件,每个项的具体打包路径用户也能自由控制。
如下 就是对应上述需求的打包描述文件src/main/assembly.xml:
&assembly&
&id&bin&/id&
&format&zip&/format&
&/formats&
&dependencySets&
&dependencySet&
&useProjectArtifact&true&/useProjectArtifact&
&outputDirectory&lib&/outputDirectory&
&/dependencySet&
&/dependencySets&
&fileSets&
&outputDirectory&/&/outputDirectory&
&includes&
&include&README.txt&/include&
&/includes&
&/fileSet&
&directory&src/main/scripts&/directory&
&outputDirectory&/bin&/outputDirectory&
&includes&
&include&run.sh&/include&
&include&run.bat&/include&
&/includes&
&/fileSet&
&/fileSets&
&/assembly&
首先这个assembly.xml文件的id对应了其最终生成文件的classifier。
其次formats定义打包生成的文件格式,这里是zip。因此结合id我们会得到一个名为hello-world-1.0-bin.zip的文件。(假设artifactId为hello-world,version为1.0)
dependencySets用来定义选择依赖并定义最终打包到什么目录,这里我们声明的一个depenencySet默认包含所有所有 依赖,而useProjectArtifact表示将项目本身生成的构件也包含在内,最终打包至输出包内的lib路径下(由 outputDirectory指定)。
fileSets允许用户通过文件或目录的粒度来控制打包。这里的第一个fileSet打包README.txt文件至包的根目录下,第二个fileSet则将src/main/scripts下的run.sh和run.bat文件打包至输出包的bin目录下。
打包描述文件所支持的配置远超出本文所能覆盖的范围,为了避免读者被过多细节扰乱思维,这里不再展开,读者若有需要可以去参考。
最后,我们需要配置maven-assembly-plugin使用打包描述文件,并绑定生命周期阶段使其自动执行打包操作:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-assembly-plugin&/artifactId&
&version&2.2.1&/version&
&configuration&
&descriptors&
&descriptor&src/main/assembly/assembly.xml&/descriptor&
&/descriptors&
&/configuration&
&executions&
&execution&
&id&make-assembly&/id&
&phase&package&/phase&
&goal&single&/goal&
&/execution&
&/executions&
运行mvn clean package之后,我们就能在target/目录下得到名为hello-world-1.0-bin.zip的分发包了。
打包是项目构建最重要的组成部分之一,本文介绍了主流Maven打包技巧,包括默认打包方式的原理、如何制作源码包和Javadoc包、如何制作命 令行可运行的CLI包、以及进一步的,如何基于个性化需求自定义打包格式。这其中涉及了很多的Maven插件,当然最重要,也是最为复杂和强大的打包插件 就是maven-assembly-plugin。事实上Maven本身的分发包就是通过maven-assembly-plugin制作的,感兴趣的读 者可以直接一窥究竟。
来源:q.com/cn/news/2011/06/xxb-maven-9-package
========================================================
自己项目:
database下包含mysql和oracle文件夹。
根目录POM.xml(配置模块和assembly打包插件):
&?xml version="1.0" encoding="utf-8"?&
&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&
&!-- Coordinate --&
&groupId&com.test.so.practice&/groupId&
&artifactId&Light2ESB&/artifactId&
&version&2.2.0&/version&
&packaging&pom&/packaging&
&!-- Info --&
&name&practice&/name&
&!-- Properties --&
&properties&
&project.build.sourceEncoding&UTF-8&/project.build.sourceEncoding&
&/properties&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-assembly-plugin&/artifactId&
&version&2.2.1&/version&
&configuration&
&descriptors&
&descriptor&assembly.xml&/descriptor&
&/descriptors&
&/configuration&
&executions&
&execution&
&id&make-assembly&/id&
&phase&package&/phase&
&goal&single&/goal&
&/execution&
&/executions&
&/plugins&
&!-- Modules --&
&module&projects&/module&
&module&servlets&/module&
&module&ejbs&/module&
&module&ear&/module&
&/modules&
&/project&
module配的是子模块文件夹名。
打包描述文件assembly.xml:
&assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"&
&id&pkg&/id&
&format&zip&/format&
&/formats&
&fileSets&
&!-- 数据库脚本 --&
&directory&${project.basedir}/database/mysql&/directory&
&/fileSet&
&!-- 资源 --&
&directory&${project.basedir}/resource&/directory&
&/fileSet&
&!-- 应用 --&
&directory&${project.basedir}/ear/ESB2Console/target/&/directory&
&includes&
&include&*.ear&/include&
&/includes&
&outputDirectory&/app/&/outputDirectory&
&/fileSet&
&directory&${project.basedir}/ear/ESB2Assistant/target/&/directory&
&includes&
&include&*.ear&/include&
&/includes&
&outputDirectory&/app/&/outputDirectory&
&/fileSet&
&directory&${project.basedir}/ejbs/com.practice.so.ws.core/target/&/directory&
&includes&
&include&*.jar&/include&
&/includes&
&outputDirectory&/app/&/outputDirectory&
&/fileSet&
&!-- 文档 --&
&directory&${project.basedir}/doc/External/&/directory&
&outputDirectory&/doc/&/outputDirectory&
&/fileSet&
&/fileSets&
&/assembly&
最后的输出包文件名为:Light2ESB-2.2.0-pkg.zip
目录如下:
其中只配directory表示将文件夹resource输出到打包文件中作为文件夹resource。如:
&directory&${project.basedir}/resource&/directory&
&/fileSet&
${project.basedir}/doc/External/
表示将doc/External下所有文件输出到doc 文件夹中。
浏览 31608
浏览: 2957065 次
来自: 一片神奇的土地
请教一下,对于Java代码
如果POST请求需要设置head ...
大神又其他网站的账号不?比如微博,知乎,或者CSDN的。
楼主文字写得太好了。
TryRelax 写道call 方法可以用来代替另一个对象调用 ...maven私服aar包的打包、上传和引用 - 简书
maven私服aar包的打包、上传和引用
maven的安装
下载地址官网下载地址:
linux下的安装下载安装包:apache-maven-3.3.9-bin.tar.gz
解压输入Linux命令:tar -xzf apache-maven-3.3.9-bin.tar.gz
设置环境变量环境变量分为用户变量和系统变量。用户变量配置文件:~/.bashrc(在当前用户主目录下的隐藏文件,可以通过ls -a查看到)系统环境配置文件:/etc/profile用户变量和系统变量的配置方法一样,本文以系统变量为例。编辑配置文件/etc/profile:输入Linux命令:sudo gedit /etc/profile
在/etc/profile文件末尾追加:# set maven environment
export M2_HOME=/home/zhengyoxin/software/apache-maven-3.3.9
export PATH=$M2_HOME/bin:$PATH
使环境变量生效输入Linux命令:source /etc/profile
验证是否成功输入Linux命令:mvn -version
成功会输出:Apache Maven 3.3.9 (bb52da5a3f4c23dc5; T00:41:47+08:00)
Maven home: /home/zhengyoxin/software/apache-maven-3.3.9
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /home/zhengyoxin/software/jdk1.8.0_25/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.16.0-70-generic", arch: "amd64", family: "unix"
使用Nexus搭建 maven 私服
下载Nexus下载地址:
在android studio中使用maven私有仓库和并上传子项目到仓库中
apply plugin: 'maven'
def MAVEN_LOCAL_PATH = 'http://192.168.200.92:8081/nexus/content/repositories/zyx/'
def ARTIFACT_ID = 'ext-map-baidu'
def VERSION_NAME = '1.0.0'
def GROUP_ID = 'com.anjubao.code'
def ACCOUNT = 'admin'
def PASSWORD = 'admin123'
//脚本:将Lib打成aar包上传至maven私有库
uploadArchives {
repositories {
mavenDeployer {
repository(url:MAVEN_LOCAL_PATH ){
authentication(userName: ACCOUNT, password: PASSWORD)}
pom.project {
groupId GROUP_ID
artifactId ARTIFACT_ID
version VERSION_NAME
packaging 'aar'
apply plugin: 'maven':添加maven插件def XXX XXX:定义字符串常量authentication(userName: ACCOUNT, password: PASSWORD)}:设置Nenux的账户和密码设置OMP:
pom.project {
groupId GROUP_ID
artifactId ARTIFACT_ID
version VERSION_NAME
packaging 'aar'
执行脚本写好脚本后,使用terminal进入Module根目录,使用gradle + task_name的方式 如: gradle uploadArchives 成功后可在web上看见生成的文件:直接运行命令:gradle uploadArchives即成功打包上传。
引用arr包如何将原来引用了子项目的项目更改为引用仓库中的arr包?
打开需要更改的项目的build.gradle文件。将compile project(':lib-common')更改为compile 'com.anjubao.code:lib-common:1.0.0'
有效明显的减少项目的构建时间。
无法查看arr包内的源码。Maven - Download Maven
Download Maven
Last Published:
Download Maven 3.0.4Maven is distributed in several formats for your convenience. Use a source archive if you intend to build Maven yourself. Otherwise, simply pick a ready-made binary distribution and follow the installation instructions given at the end of this document.You will be prompted for a mirror - if the file is not found on yours, please be patient, as it may take 24 hours to reach all mirrors.In order to guard against corrupted downloads/installations, it is highly recommended to
of the release bundles against the public
used by the Apache Maven developers.Maven is distributed under the .We strongly encourage our users to configure a Maven repository mirror closer to their location, please read .Be sure to check the
before using this version to avoid surprises. While Maven 3 aims to be backward-compatible with Maven 2.x to the extent possible, there are still a few significant changes.MirrorsChecksumSignatureMaven 3.0.4 (Binary tar.gz)Maven 3.0.4 (Binary zip)Maven 3.0.4 (Source tar.gz)Maven 3.0.4 (Source zip)Release NotesRelease Reference DocumentationYou can also download the current documentation, i.e. this website, as a .This is an older, but stable version of Maven for projects that can't upgrade to Maven 3.x yet.MirrorsChecksumSignatureMaven 2.2.1 (Binary tar.gz)Maven 2.2.1 (Binary zip)Maven 2.2.1 (Source tar.gz)Maven 2.2.1 (Source zip)Release NotesRelease Reference DocumentationThis is an older, but stable version of Maven for projects that require Maven to run on JDK 1.4.MirrorsChecksumSignatureMaven 2.0.11 (Binary tar.gz)Maven 2.0.11 (Binary zip)Maven 2.0.11 (Source tar.gz)Maven 2.0.11 (Source zip)Release NotesRelease Reference DocumentationYou can download the current documentation, i.e. this website, as:a
file.Previous ReleasesAll previous releases of Maven can be found in the .System JDK1.5 or above (this is to execute Maven - it still allows you to build against 1.3 and prior JDK's)MemoryNo minimum requirementDiskNo minimum requirement. Approximately 100MB will be used for your local repository, however this will vary depending on usage and can be removed and redownloaded at any time.Operating SystemNo minimum requirement. On Windows, Windows NT and above or Cygwin is required for the startup scripts. Tested on Windows XP, Fedora Core and Mac OS X. InstructionsMaven is a Java tool, so you must have
installed in order to proceed. More precisely, you need a Java Development Kit (JDK), the Java Runtime Environment (JRE) is not sufficient.Additional optional installation steps are listed after the platform specific instructions.Windows 2000/XPUnzip the distribution archive, i.e. apache-maven-3.0.4-bin.zip to the directory you wish to install Maven 3.0.4. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.0.4 will be created from the archive.Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the &Advanced& tab, and the &Environment Variables& button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.0.4. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven & 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.Unix-based Operating Systems (Linux, Solaris and Mac OS X)Extract the distribution archive, i.e. apache-maven-3.0.4-bin.tar.gz to the directory you wish to install Maven 3.0.4. These instructions assume you chose /usr/local/apache-maven. The subdirectory apache-maven-3.0.4 will be created from the archive.In a command terminal, add the M2_HOME environment variable, e.g. export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.4.Add the M2 environment variable, e.g. export M2=$M2_HOME/bin.Optional: Add the MAVEN_OPTS environment variable to specify JVM properties, e.g. export MAVEN_OPTS=&-Xms256m -Xmx512m&. This environment variable can be used to supply extra options to Maven.Add M2 environment variable to your path, e.g. export PATH=$M2:$PATH.Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.5.0_02 and that $JAVA_HOME/bin is in your PATH environment variable.Run mvn --version to verify that it is correctly installed.Optional configurationMaven will work for most tasks with the above configuration, however if you have any environmental specific configuration outside of individual projects then you will need to configure settings. The following sections refer to what is available.SettingsMaven has a settings file located in the Maven installation and/or user home directory that configure environmental specifics such as:HTTP proxy serverrepository manager locationserver authentication and passwordsother configuration propertiesFor information on this file, see the SecurityAs of Maven 2.1.0+, you can encrypt passwords in your settings file, however you must first configure a master password. For more information on both server passwords and the master password, see the .ToolchainsAs of Maven 2.0.9+, you can build a project using a specific version of JDK independent from the one Maven is running with. For more information, see the .> 博客详情
摘要: 材料:apache-maven-3.3.9-bin.tar.gz
安装maven很简单和JDK的安装差不多,不过需要注意的是maven依赖JDK所以装maven 前先装jdk
JDK安装请参考:
接下来安装maven:
1、解压安装文件(创建安装文件目录,便于管理,您也可以不用键就在当前文件下解压)
# &mkdir &-p /opt/usr/local/maven
# &tar &-zxvf &apache-maven-3.3.9-bin.tar.gz &-C&&/opt/usr/local/maven & &注意:-C 为大写
2、设置环境变量
# &vi /etc/profile&
注:进入profile 之后按 i 键进行编辑,Esc 键进入命令模式输出&:wq! 保存并退出
写入以下配置:
export M2_HOME=/opt/usr/local/maven/apache-maven-3.3.9
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$M2_HOME/bin:$PATH
3、执行profile让新配置生效
# &source&/etc/profile&
4、检查是否安装成功
注:如果出现maven版本信息便表示成功
人打赏支持
码字总数 27414
支付宝支付
微信扫码支付
打赏金额: ¥
已支付成功
打赏金额: ¥}

我要回帖

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信