对于不包含MANIFEST.MF,或jar包中的MANIFEST.MF未指定MainClass的jar,可以通过java命令行选项-classpath指定classpath。但是如果是包含MainClass的jar,例如:

Manifest-Version: 1.0
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-SymbolicName: org.mybatis.generator.mybatis-generator-core
Archiver-Version: Plexus Archiver
Built-By: zjhua
Bnd-LastModified: 1559632976998
Specification-Title: MyBatis Generator Core
Implementation-Vendor-Id: org.mybatis.generator
Bundle-DocURL: http://www.mybatis.org/mybatis-generator/mybatis-genera
tor-core/
Include-Resource: org/mybatis/generator/config/xml/ibator-config_1_0.d
td=src/main/resources/org/mybatis/generator/config/xml/ibator-config_
1_0.dtd,org/mybatis/generator/config/xml/mybatis-generator-config_1_0
.dtd=src/main/resources/org/mybatis/generator/config/xml/mybatis-gene
rator-config_1_0.dtd,org/mybatis/generator/internal/util/messages/mes
sages.properties=src/main/resources/org/mybatis/generator/internal/ut
il/messages/messages.properties
Import-Package: com.mysql.jdbc,javax.xml.parsers,org.apache.commons.la
ng3,org.apache.log4j,org.apache.tools.ant,org.apache.tools.ant.types,
org.w3c.dom,org.xml.sax
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))"
Main-Class: org.mybatis.generator.api.ShellRunner
Implementation-Build-Date: 2019-06-04 07:22:46+0000

其classpath可以通过maven打包插件指定,如下:

            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.xxx.uploadFile</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

这样和jar文件在同一目录的lib/下的所有jar就都是能够访问到了。

然后我们通过maven-dependency-plugin插件将特定的包拷贝到lib目录,如下:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<outputDirectory>${project.build.directory}/lib/lib1</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
<outputDirectory>${project.build.directory}/lib/lib1</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

也可以拷贝所有依赖,如下:

 <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>

实际情况是我们通常希望基础三方库打到包中,应用jar拷贝到lib目录,同时兼顾易升级和管理复杂性,所以最终是这样的。

            <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<mainClass>org.abc.ConsumerStarter</mainClass>
<excludes>
<exclude>
<groupId>abc.org</groupId>
<artifactId>biz-service</artifactId>
</exclude>
</excludes>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>abc.org</groupId>
<artifactId>biz-service</artifactId>
<version>1.1.0</version>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

这样打出来的jar就不包含biz-service,在单独的lib目录中。结合layout ZIP特性,就可以完美实现增量升级。

最新文章

  1. 野比的示波器案例(Winfrom用户控件)
  2. Python中的__new__()方法的使用
  3. C++ 模板类解析
  4. c# DataTable 中 Select 和 Clone 用法结合
  5. vs2010的一个opencv插件
  6. JVM体系结构
  7. php回调函数callback函数实例
  8. back_insert_iterator和iterator用起来不一样。
  9. Oracle学习(十四):管理用户安全性
  10. android入门,activity跳转,并传递message
  11. 各种电脑进入BIOS快捷键
  12. split函数用法
  13. 列表 ul ol dl 和 块级标签和行及标签之间的转换
  14. cpp 区块链模拟示例(五) 序列化
  15. BZOJ2243 洛谷2486 [SDOI2011]染色 树链剖分
  16. 关于RabbitMQ关键性问题的总结
  17. 分布式锁实现思路及开源项目集成到springmvc并使用
  18. 动态链接库DLL_第1篇
  19. Wpf中显示Unicode字符
  20. CF1017G The Tree 树链剖分

热门文章

  1. 图说jdk1.8新特性(3)--- 注解与类型推测优化
  2. [LeetCode] 543. 二叉树的直径 ☆(递归、数最大深度)
  3. scrapy 爬虫中间件 deepth深度
  4. MySQL Index--Change Buffer
  5. 程序员的选房神技,GitHub上的房源爬虫
  6. FreeBSD关机后自动重启的解决办法
  7. 25.centos7基础学习与积累-011-课前考试二-命令练习
  8. nginx负载调度算法,后端节点状态
  9. vscode编写html,常用快捷方式与插件
  10. CyclicBarrier 使用详解