maven项目打包
来源:互联网 发布:淘宝拍卖车辆是真的吗 编辑:程序博客网 时间:2024/05/18 03:51
现欲将项目源码打成可执行jar包,但不将(resources)资源文件打入jar包,而是在jar包中指定classpath,那么如何编写POM文件呢?
项目的结构是:
-src
-----main
--------+java
--------+sources
--------+webapp
----+test
现需要打成一个可执行的jar包,运行时的结构如下:
-work
----+lib
----+resources
-----runnable.jar
-----run.sh
并且run.sh中,启动命令类型于:java -jar runnable.jar
runnable.jar的MANIFEST.MF文件里的内容,类似如下图,注意哦,不仅有依赖的jar包还有resources:
本博文参考自:http://www.jianshu.com/p/afb79650b606
下面直接贴出POM脚本
<build> <finalName>dataMigration</finalName> <resources> <resource> <directory>src/main/resources</directory> </resource> <resource> <directory>${profiles.dir}/${deploy.type}</directory> <targetPath>META-INF</targetPath> </resource> </resources> <plugins> <!-- 项目依赖插件 --> <plugin> <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以外的所有文件到conf/目录下 --> <outputDirectory>${project.build.directory}/resources</outputDirectory> <resources> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> <excludes> <exclude>*.bat</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/目录下所有文件到输出目录下 --> <outputDirectory>${project.build.directory}</outputDirectory> <resources> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> <!-- 打包插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <!-- 生成MANIFEST.MF的设置 --> <manifest> <!-- 为依赖包添加路径, 这些路径会写在MANIFEST文件的Class-Path下 --> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <!-- jar启动入口类--> <mainClass>MigrateLauncher</mainClass> </manifest> <manifestEntries> <!-- 在Class-Path下添加配置文件的路径 --> <Class-Path>resources/</Class-Path> </manifestEntries> </archive> <includes> <!-- 打jar包时,只打包class文件 --> <include>**/*.class</include> </includes> </configuration> </plugin> <!-- Compiler plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> <version>3.5.1</version> </plugin> </plugins> </build>
1 0
- Maven 项目打包发布
- maven项目打包配置
- maven项目打包异常
- Maven项目打包杂谈
- Maven 项目打包发布
- Maven 项目打包发布
- maven项目打包步骤
- maven项目打包
- maven项目打包命令
- maven项目打包运行
- maven项目打包注意事项
- maven打包项目
- maven项目打包
- maven项目打包
- maven 打包依赖项目
- Maven打包项目配置
- Maven 项目打包
- IDEA 打包maven 项目
- HTML基础:我的第一个网页(1)
- CSS ::before 和 ::after
- “因为好玩” ——YPA(名言)
- winform简单的UI和数据异步加载
- LSGO:祝大家新年快乐!
- maven项目打包
- Leetcode 367. Valid Perfect Square
- try catch finally 细节
- java 包与包之间访问
- 为什么你有10年经验,但成不了专家?(转载)
- GoodBye2016C. New Year and Rating
- ArcGis for android
- ffmpeg flv直播发送的一点感悟
- 网页Ico小图片乱码