Maven分离配置、依赖
来源:互联网 发布:大华网络监控安装步骤 编辑:程序博客网 时间:2024/06/13 10:06
在用Maven打包项目时,要像Hadoop、Spark、Hive等项目打包之后的文件包含bin、lib、conf之类的文件夹,同时可以动态的修改项目的配置参数,需要如下两步:
- 在 pom.xml 文件中引入 maven-assembly 插件;
- 在 assembly.xml 文件中制定各个文件目录。
pom.xml引入maven-assembly插件
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <appendAssemblyId>true</appendAssemblyId> <descriptors> <descriptor>src/assembly/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>maven-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions></plugin>
<?xml version="1.0" encoding="UTF-8"?><assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd"> <id>all</id> <formats> <format>tar.gz</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>bin</directory> <outputDirectory>bin</outputDirectory> <fileMode>755</fileMode> </fileSet> <fileSet> <directory>src/main/resources</directory> <outputDirectory>conf</outputDirectory> <fileMode>755</fileMode> <lineEnding>unix</lineEnding> <excludes> <exclude>*.formatted</exclude> </excludes> </fileSet> </fileSets> <dependencySets> <dependencySet> <fileMode>755</fileMode> <outputDirectory>lib</outputDirectory> <scope>runtime</scope> <useProjectArtifact>false</useProjectArtifact> <excludes> <exclude>${project.groupId}:${project.artifactId}</exclude> </excludes> </dependencySet> <dependencySet> <fileMode>755</fileMode> <outputFileNameMapping>${project.artifactId}.jar</outputFileNameMapping> <outputDirectory>/lib/</outputDirectory> <scope>runtime</scope> <includes> <include>${project.groupId}:${project.artifactId}</include> </includes> </dependencySet> </dependencySets></assembly>
不难发现,我们把打好的程序jar包也放到了 lib目录 中。
执行代码
用这种方法打的jar包,是不包含依赖的jar包和配置文件的。所以,在执行之前需要把依赖的jar包和配置文件加入到 $CLASSPATH 中,Shell脚本如下:
#!/usr/bin/env bashBIN=`dirname $0`BIN=`cd $BIN; pwd`APP_HOME=`dirname $BIN`JAVA=${JAVA_HOME}/bin/javaCLASSPATH=${APP_HOME}/conf#JAR=${APP_HOME}/tools.jarfor f in ${APP_HOME}/lib/*.jar; do CLASSPATH=${CLASSPATH}:$fdonefor f in ${APP_HOME}/*.jar; do CLASSPATH=${CLASSPATH}:$fdoneMAINCLASS="edu.wzm.joda.JodaDemo"exec "$JAVA" -classpath $CLASSPATH $MAINCLASS
0 0
- Maven分离配置、依赖
- Maven分离配置、依赖
- Maven 配置 Storm 第三方依赖包分离
- IntelliJ IDEA用maven自动打jar包配置(程序和依赖包分离)
- Maven依赖的配置
- Maven排除依赖配置
- Maven -- 依赖范围配置
- Maven依赖的配置
- Log4j maven依赖配置
- maven打包以及配置分离
- Java maven 打包配置分离
- Maven依赖配置和依赖范围
- Maven jar包依赖配置
- Maven多项目依赖配置
- 配置Jstl的Maven依赖
- maven配置依赖本地项目
- Maven多项目依赖配置
- Maven多项目依赖配置
- /include/linux/usb.h
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags 贪心、字符串处理
- 系统之间共享cookie的要求
- 跨域解决方法之window.name
- 五中常规的网页布局方式
- Maven分离配置、依赖
- hdu 2647 Reward
- Maven 学习
- CSU-1011
- Qt进度条提示对话框
- PAT A1004. Counting Leaves (30)
- iOS 去掉字符串中特殊字符
- java
- 迷你TXT小说阅读器 V2.8 内测3 发布!