本文主要是介绍03 为什么 Bootstrap 代理之后能使用 maven 来管理 rcp 项目的依赖,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言
呵呵 这里会大致的跟一些 可能有帮助于理解 使用 maven 来管理 rcp 项目的依赖 的一些记录信息
当然 不了解也没关系
业务代码使用 sqlite.JDBC
看 sqlite.JDBC 的加载
可以看到的是 Activator 触发了 sqlite.JDBC 的加载
这里面的 Classloader 实例, ModuleClassLoader 的实例, 实际上的实现是 org.eclipse.osgi.internal.loader.EquinoxClassLoader
可以看到这一系列的加载非常复杂, 我们还是看一些重点吧, 类加载的路由部分主要是委托给了这里的 ClasspathManager 来寻找
从下面的图片也可以看到, 这里的 cpEntries 大概是有 31 个, 对应的就是 各个 jar, 也就是我们 pom.xml 里面配置的各个 plugin.jar 以及 sqlite.jar 以及 commons-io.jar 可以参见后面的 "cpEntries 包含了那些?"
可以看到的是在 /Users/jerry/.m2/repository/org/xerial/sqlite-jdbc/3.32.3.2/sqlite-jdbc-3.32.3.2.jar 中发现了 sqlite.JDBC, 然后 就走了后面的从 sqlite-jdbc-3.32.3.2.jar 中加载 sqlite.JDBC defineClass 的相关流程
cpEntries 包含了那些数据?
我们这里吧 cpEntries 列出来 大致的结构是
*.plugin.* 相关的差不多是 24 个依赖
sqlite.jar, commons-io.jar 两个业务依赖
idea_rt.jar 一个 jdk 的基础依赖
$base.dir/target/classes, $base.dir, $base.dir[target/classes], $base.dir/libs/sqlite.jar 四个其他依赖
0 = "/Users/jerry/EclipseWorkStations/MyRcp/target/classes"
1 = "/Users/jerry/.p2/pool/plugins/org.eclipse.equinox.launcher_1.6.0.v20200915-1508.jar"
2 = "/Users/jerry/.p2/pool/plugins/javax.inject_1.0.0.v20091030.jar"
3 = "/Users/jerry/.p2/pool/plugins/org.eclipse.swt_3.115.100.v20201202-1103.jar"
4 = "/Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.model.workbench_2.1.900.v20201014-0742.jar"
5 = "/Users/jerry/.p2/pool/plugins/org.eclipse.jface_3.22.0.v20201106-0834.jar"
6 = "/Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.services_1.4.0.v20201014-0944.jar"
7 = "/Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.workbench_1.12.0.v20201119-1132.jar"
8 = "/Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.di_1.7.600.v20200428-0912.jar"
9 = "/Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.di_1.2.900.v20201021-1339.jar"
10 = "/Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.contexts_1.8.400.v20191217-1710.jar"
11 = "/Users/jerry/.p2/pool/plugins/org.eclipse.core.runtime_3.20.0.v20201027-1526.jar"
12 = "/Users/jerry/.p2/pool/plugins/org.eclipse.core.commands_3.9.800.v20201021-1339.jar"
13 = "/Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.di.annotations_1.6.600.v20191216-2352.jar"
14 = "/Users/jerry/.p2/pool/plugins/org.eclipse.osgi_3.16.100.v20201030-1916.jar"
15 = "/Users/jerry/.p2/pool/plugins/org.eclipse.osgi.compatibility.state_1.2.200.v20200915-2015.jar"
16 = "/Users/jerry/.p2/pool/plugins/org.eclipse.equinox.common_3.14.0.v20201102-2053.jar"
17 = "/Users/jerry/.p2/pool/plugins/org.eclipse.core.jobs_3.10.1000.v20200909-1312.jar"
18 = "/Users/jerry/.p2/pool/plugins/org.eclipse.equinox.registry_3.10.0.v20201107-1818.jar"
19 = "/Users/jerry/.p2/pool/plugins/org.eclipse.equinox.preferences_3.8.100.v20201102-2042.jar"
20 = "/Users/jerry/.p2/pool/plugins/org.eclipse.core.contenttype_3.7.800.v20200724-0804.jar"
21 = "/Users/jerry/.p2/pool/plugins/org.eclipse.equinox.app_1.5.0.v20200717-0620.jar"
22 = "/Users/jerry/.p2/pool/plugins/javax.annotation_1.3.5.v20200909-1856.jar"
23 = "/Users/jerry/.p2/pool/plugins/org.eclipse.swt.browser.chromium.cocoa.macosx.x86_64_3.115.100.v20201202-1103.jar"
24 = "/Users/jerry/.p2/pool/plugins/org.eclipse.swt.cocoa.macosx.x86_64_3.115.100.v20201202-1103.jar"
25 = "/Users/jerry/.m2/repository/org/xerial/sqlite-jdbc/3.32.3.2/sqlite-jdbc-3.32.3.2.jar"
26 = "/Users/jerry/.m2/repository/commons-io/commons-io/2.6/commons-io-2.6.jar"
27 = "/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar"
28 = "/Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/EclipseWorkStations/MyRcp[target/classes/]"
29 = "/Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/EclipseWorkStations/MyRcp"
30 = "/Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/EclipseWorkStations/MyRcp/libs/sqlite-jdbc-3.32.3.2.jar"
ClasspathManager 里面的 cpEntries 来自于哪里?
ClasspathManager 的创建是在 EquinoxClassLoader 里面
我们在 ClasspathManager 里面打上断点
... 然后我们会发现 N 个进入 ClasspathManager 的断点?, 创建了这么多的 EquinoxClassLoader ?
我们可以稍微打印一下这些 EquinoxClassLoader 的相关上下文信息, 一些是 *.plugin.*, 另外还有一个而我们需要关注的 MyRcp
entryLength = 31, firstBundle = /Users/jerry/EclipseWorkStations/MyRcp/target/classes
inClasspathManager - entryLength = 1, firstBundle = /Users/jerry/.p2/pool/plugins/org.eclipse.osgi_3.16.100.v20201030-1916.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.apache.felix.scr_2.1.24.v20200924-1939.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.osgi.services_3.9.0.v20200511-1725.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.equinox.common_3.14.0.v20201102-2053.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.osgi.util_3.5.300.v20190708-1141.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.core.contenttype_3.7.800.v20200724-0804.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.equinox.preferences_3.8.100.v20201102-2042.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.equinox.registry_3.10.0.v20201107-1818.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.di.extensions.supplier_0.15.700.v20200622-1247.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.di_1.7.600.v20200428-0912.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.core.runtime_3.20.0.v20201027-1526.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.equinox.app_1.5.0.v20200717-0620.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.equinox.event_1.5.500.v20200616-0800.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.workbench.swt_0.15.0.v20201103-0952.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.jface_3.22.0.v20201106-0834.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.model.workbench_2.1.900.v20201014-0742.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.services_2.2.500.v20200928-2213.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.workbench_1.12.0.v20201119-1132.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.contexts_1.8.400.v20191217-1710.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.swt_3.115.100.v20201202-1103.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.services_1.4.0.v20201014-0944.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/javax.inject_1.0.0.v20091030.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.di.annotations_1.6.600.v20191216-2352.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/javax.annotation_1.3.5.v20200909-1856.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.emf.ecore_2.23.0.v20200630-0516.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.emf.common_2.21.0.v20200917-1439.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.emf.ecore.xmi_2.16.0.v20190528-0725.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.emf.ecore.change_2.14.0.v20190528-0725.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.emf.xpath_0.2.800.v20200609-0849.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.emf.databinding_1.5.0.v20180706-1146.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.workbench.renderers.swt_0.15.0.v20201125-0918.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.workbench.addons.swt_1.4.0.v20201119-1132.jarinClasspathManager - entryLength = 31, firstBundle = /Users/jerry/EclipseWorkStations/MyRcp/target/classesinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.core.commands_3.9.800.v20201021-1339.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.core.databinding.observable_1.10.0.v20200730-0848.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.jface.databinding_1.12.100.v20201014-0742.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.di_1.2.900.v20201021-1339.jar
org.sqlite.JDBC
E4LifeCycle.postContextCreateinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.commands_0.13.0.v20201119-1132.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.bindings_0.13.0.v20201119-1132.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.core.di.extensions_0.16.0.v20200507-0938.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.css.core_0.13.0.v20201015-0653.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.css.swt.theme_0.13.0.v20201026-1147.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.css.swt_0.14.0.v20201103-0952.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.w3c.css.sac_1.3.1.v200903091627.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.apache.batik.css_1.13.0.v20200622-2037.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.apache.batik.i18n_1.13.0.v20200622-2037.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.apache.batik.util_1.13.0.v20200622-2037.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.widgets_1.2.800.v20201021-1339.jarinClasspathManager - entryLength = 1, firstBundle = /Applications/Eclipse.app/Contents/Eclipse/../../../../Users/jerry/.p2/pool/plugins/org.eclipse.e4.ui.workbench3_0.15.500.v20201021-1339.jar
这些 module 来自于 /Users/jerry/EclipseWorkStations/.metadata/.plugins/org.eclipse.pde.core/MyRcp.product/org.eclipse.osgi/framework.info.8 解析出来的 module 部分的信息
这个文件里面包含了 一些常规信息, 版本, 时间, 权限信息, 以及这里的 模块的相关信息, 具体的过程可以参见 Storage.<init>
回到主题, 我们这里需要关注的是 MyRcp 对应的这个 EquinoxClassLoader
读取 MyRcp 对应的额 classpath 读取出来的数据大致如下, 看起来就是 dev.properties 里面的配置
配置的加载来自于 初始化 EquinoxConfiguration 的时候, 配置文件来自于 osgi.dev 的配置
这个 osgi.dev 的配置 来自于参入的 程序参数[Program arguments]
扩展
现在能够反向的理解 使用 maven 来管理 rcp 项目的依赖 了么?
至于我最开始怎么知道修改 dev.properties 的? 你猜 ~ little tricks[占位符]
完
参照
使用 maven 来管理 rcp 项目的依赖
这篇关于03 为什么 Bootstrap 代理之后能使用 maven 来管理 rcp 项目的依赖的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!