maven常用打包插件
来源:互联网 发布:睿捷决策软件 编辑:程序博客网 时间:2024/05/02 00:15
1.使用maven的时候,有时候会遇到各种打包的情况,下面总结了常用的几个打包插件,一般情况下已经够用了。<build> <finalName>SxInnovate</finalName><!--打包出来的文件名--> <plugins> <plugin><!--编译插件--> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> <compilerArguments> <verbose /> <bootclasspath>${java.home}/lib/rt.jar</bootclasspath> </compilerArguments> </configuration> </plugin> <plugin><!--打包依赖的jar包--> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <!-- 表示是否不包含间接依赖的包 --> <stripVersion>false</stripVersion> <!-- 去除版本信息 --> </configuration>
<executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!-- 拷贝项目依赖包到lib/目录下 --> <outputDirectory>${project.build.directory}/lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> </configuration> </execution> </executions> </plugin>
<!-- 项目资源插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <!-- 拷贝项目src/main/resources/下,除.bat和.sh以外的所有文件到conf/目录下 --> <outputDirectory>${project.build.directory}/conf</outputDirectory> <resources> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> <excludes> <exclude>*.bat</exclude> <exclude>*.sh</exclude> </excludes> </resource> </resources> </configuration> </execution> <execution> <id>copy-command</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <!-- 只拷贝项目src/main/resources/目录下的.bat文件到输出目录下 --> <outputDirectory>${project.build.directory}/bin</outputDirectory> <resources> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> <includes> <include>*.bat</include> <include>*.sh</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
<!-- 打成jar包插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <!-- 生成的jar中,不要包含pom.xml和pom.properties这两个文件 --> <addMavenDescriptor>false</addMavenDescriptor> <!-- 生成MANIFEST.MF的设置 --> <manifest> <!-- 为依赖包添加路径, 这些路径会写在MANIFEST文件的Class-Path下 --> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <!-- jar启动入口类--> <mainClass>com.boco.Application</mainClass> </manifest> <manifestEntries> <!-- 在Class-Path下添加配置文件的路径 --> <Class-Path>conf/</Class-Path> </manifestEntries> </archive> <outputDirectory>${project.build.directory}/</outputDirectory> <includes> <!-- 打jar包时,只打包class文件 --> <include>**/*.class</include> </includes> </configuration> </plugin><!--打包插件,这个功能很强大,具体可以网上搜一下--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <!-- The configuration of the plugin --> <configuration> <!-- Specifies the configuration file of the assembly plugin --> <descriptors> <descriptor>package.xml</descriptor> </descriptors> <!--<descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef>依赖包和源码打成一个jar文件 </descriptorRefs>--> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>上面的package.xml文件内容如下:<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> <id>distribution</id> <formats> <format>zip</format> </formats>
<fileSets> <fileSet> <directory>${project.basedir}\src\main\resources</directory> <outputDirectory>\conf</outputDirectory> <!-- <includes> <include>${project.basedir}\lib</include> </includes>-->
<!--<excludes> <exclude>some/path1</exclude> </excludes>--> </fileSet>
<fileSet> <directory>${project.basedir}\src\bin</directory> <outputDirectory>\bin</outputDirectory> </fileSet>
<fileSet> <directory>${project.basedir}\lib</directory> <outputDirectory>\lib</outputDirectory> </fileSet> </fileSets>
<dependencySets> <dependencySet> <useProjectArtifact>true</useProjectArtifact> <outputDirectory>lib</outputDirectory> <!-- 将scope为runtime的依赖包打包到lib目录下。 --> <scope>runtime</scope> </dependencySet> </dependencySets></assembly>
另外,两个小知识点:1.将本地jar安装到本地仓库,解决像oracle连接驱动引用不了的问题。mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.2.0 -Dpackaging=jar -Dfile=E:\oracle\ojdbc14-10.2.0.2.0.jar2.项目依赖本地路径jar包首先我在项目根目录中创建一个lib文件夹,将jar包拷贝到lib文件夹下
然后我们在maven的pom.xml中配置
<groupId>org.aaa.bbb</groupId>
<artifactId>kkk</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/aaa.jar</systemPath> 这里的groupId和artifactId以及version都是可以随便填写的 ,scope必须填写为system,而systemPath我们现在我们jar包的地址就可以了
1.使用maven的时候,有时候会遇到各种打包的情况,下面总结了常用的几个打包插件,一般情况下已经够用了。
<build>
<finalName>SxInnovate</finalName><!--打包出来的文件名-->
<plugins>
<plugin><!--编译插件-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<verbose />
<bootclasspath>${java.home}/lib/rt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin><!--打包依赖的jar包-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive> <!-- 表示是否不包含间接依赖的包 -->
<stripVersion>false</stripVersion> <!-- 去除版本信息 -->
</configuration>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 拷贝项目依赖包到lib/目录下 -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<!-- 项目资源插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<!-- 拷贝项目src/main/resources/下,除.bat和.sh以外的所有文件到conf/目录下 -->
<outputDirectory>${project.build.directory}/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
<excludes>
<exclude>*.bat</exclude>
<exclude>*.sh</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-command</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<!-- 只拷贝项目src/main/resources/目录下的.bat文件到输出目录下 -->
<outputDirectory>${project.build.directory}/bin</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
<includes>
<include>*.bat</include>
<include>*.sh</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- 打成jar包插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<!--
生成的jar中,不要包含pom.xml和pom.properties这两个文件
-->
<addMavenDescriptor>false</addMavenDescriptor>
<!-- 生成MANIFEST.MF的设置 -->
<manifest>
<!-- 为依赖包添加路径, 这些路径会写在MANIFEST文件的Class-Path下 -->
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<!-- jar启动入口类-->
<mainClass>com.boco.Application</mainClass>
</manifest>
<manifestEntries>
<!-- 在Class-Path下添加配置文件的路径 -->
<Class-Path>conf/</Class-Path>
</manifestEntries>
</archive>
<outputDirectory>${project.build.directory}/</outputDirectory>
<includes>
<!-- 打jar包时,只打包class文件 -->
<include>**/*.class</include>
</includes>
</configuration>
</plugin>
<!--打包插件,这个功能很强大,具体可以网上搜一下-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<!-- The configuration of the plugin -->
<configuration>
<!-- Specifies the configuration file of the assembly plugin -->
<descriptors>
<descriptor>package.xml</descriptor>
</descriptors>
<!--<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>依赖包和源码打成一个jar文件
</descriptorRefs>-->
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
上面的package.xml文件内容如下:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}\src\main\resources</directory>
<outputDirectory>\conf</outputDirectory>
<!-- <includes>
<include>${project.basedir}\lib</include>
</includes>-->
<!--<excludes>
<exclude>some/path1</exclude>
</excludes>-->
</fileSet>
<fileSet>
<directory>${project.basedir}\src\bin</directory>
<outputDirectory>\bin</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}\lib</directory>
<outputDirectory>\lib</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<!-- 将scope为runtime的依赖包打包到lib目录下。 -->
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
另外,两个小知识点:
1.将本地jar安装到本地仓库,解决像oracle连接驱动引用不了的问题。
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.2.0 -Dpackaging=jar -Dfile=E:\oracle\ojdbc14-10.2.0.2.0.jar
2.项目依赖本地路径jar包
首先我在项目根目录中创建一个lib文件夹,将jar包拷贝到lib文件夹下
然后我们在maven的pom.xml中配置
<groupId>org.aaa.bbb</groupId>
<artifactId>kkk</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/aaa.jar</systemPath>
<artifactId>kkk</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/aaa.jar</systemPath>
这里的groupId和artifactId以及version都是可以随便填写的 ,scope必须填写为system,而systemPath我们现在我们jar包的地址就可以了
1 0
- maven常用打包插件
- Maven 打包源代码插件
- maven 插件动态打包
- maven 打包插件
- maven的打包插件
- maven打包插件:appassembler
- Maven打包常用操作
- maven常用插件: 打包源码 / 跳过测试 / 单独打包依赖项
- maven常用插件: 打包源码 / 跳过测试 / 单独打包依赖项
- maven常用插件: 打包源码 / 跳过测试 / 单独打包依赖项
- maven常用插件: 打包源码 / 跳过测试 / 单独打包依赖项
- maven常用插件: 打包源码 / 跳过测试 / 单独打包依赖项
- 【maven常用插件】打包源码 / 跳过测试 / 单独打包依赖项
- Webpack打包常用插件
- Eclipse的插件Maven打包
- Maven-----源码、JavaDoc打包插件
- Maven Assembly打包插件介绍
- maven+assembly插件打包应用程序
- rabbit Mq笔记
- Android学习笔记(十九)分享简单数据
- 第五周项目1-建立顺序栈算法库
- 大数据学习笔记-------------------(12_1)
- 第五周项目一(建立顺序栈算法库)
- maven常用打包插件
- POJ 2151 概率DP
- maven生成jar包以及相应的报错
- 第5周项目1 Raptor(7)
- 留言板,各路大神求留言
- 第四周 项目三-单链表应用(一)
- web前端-HTML链接-007
- 【codevs 1026】逃跑的拉尔夫
- 数据分析师养成记-python做数据分析(一)