如果我不想在 osgi 中使用 jar,我该如何找到一个类
我使用 java 命令运行 osgi: java -jar org.eclipse.osgi_3.5.1.R35x_v20090827.jar -console 然后可以在 ./plugins 目录中找到捆绑包。
有 2 个问题。 (1)我刚刚在本地机器中编辑了1个类文件并将其传输到远程服务器。所以我想osgi只加载类而不是jar。我该怎么办呢?如果osgi框架不支持这个功能。我必须打包只编辑了一个类文件的jar并将其传输到远程服务器。打包和转移整个罐子的速度很慢。
(2)当我在后台运行命令时。我怎样才能再次获得osgi控制台?
i run the osgi using the java command:
java -jar org.eclipse.osgi_3.5.1.R35x_v20090827.jar -console
and then the bundles could be find in the ./plugins directory.
There are 2 questions.
(1)I just edited 1 class file in the local machine and transfered it to the remote server. so I want to osgi just load the classes not the jar. how should I do it ? if the osgi framework didn't support this feature. I must package the jar which has only one class file edited and transfer it to remote server. it is to slow to package it and transfer the whole jar.
(2)when I run the command in background. how could I get the osgi console again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可能有非标准的方法来加载类,但没有办法用纯 OSGi 来做到这一点。在 OSGi 中,捆绑包(jar 文件)是可由 OSGi 框架加载和管理的交付包。通常,每个包都由单独的类加载器加载。
您可以从中获益良多:您可以指定捆绑包导出或导入哪个版本的软件包。在清单中,您以有序的方式指示这些关系。这样,OSGi 框架就能够在不中断其他包的情况下管理依赖关系。
There might be non-standard ways to load classes, but there is no ways to do that with pure OSGi. In OSGi the bundle (the jar file) is the delivery package that can be loaded and managed by an OSGi framework. Usually, each bundle is loaded by an separate classloader.
You gain a lot with that: you specify which packages with which version a bundle exports or imports. In the Manifest you indicate these relationships in an orderly manner. This ways the OSGi framework is able to manage the dependencies without interrupting other bundles.
如果您尝试替换该类以进行调试,则可以尝试在支持热代码替换的虚拟机上进行远程调试。这将允许您逐步执行、发现问题并修复它,而无需重新启动 OSGi。
一旦找到修复程序,您将需要重建捆绑包。 @akr 是正确的,OSGi 的打包机制是捆绑。
要回答您的第二个问题,如果您需要控制台,请不要在后台运行它。只需在其自己的 shell 中运行该命令即可。在开发时,这应该不是问题。在部署时,您不应该真正使用控制台来执行操作。 Eclipse 中的 P2 等技术可以帮助管理已部署的 OSGi 运行时。
If you are trying to replace the class for debugging purposes, you could try a remote debug on a VM that supports hot code replace. This will allow you to step through, find a problem, and fix it without restarting OSGi.
Once you find the fix though, you will need to rebuild the bundle. @akr is correct that the packaging mechanism for OSGi is bundles.
To answer your second question, don't run it in the background if you want the console. Just run the command in its own shell. At development time, this shouldn't be a problem. At deployment time, you shouldn't really be using the console to do things. Technologies like P2 from Eclipse can help with managing deployed OSGi runtimes.
回答问题 2:OSGi 有支持 telnet 和 SSH 的 shell。使用其中之一可以让您在后台运行该进程,但仍然连接到它(甚至是远程连接)。
Answering question 2: there are shells for OSGi that support telnet and SSH. Using one of those allows you to run the process in the background but still connect to it (even remotely obviously).
如果您使用bundleContext.installBundle(String location)来安装您的bundle,您可以在服务器上定义一个解压jar包的文件夹。之后,您可以仅将该类复制到服务器文件夹并对该包调用更新命令。
如果您将 Eclipse 与 m2e 和 maven-bundle-plugin 一起使用,您可以在保存类后立即将 target/classes 目录同步到服务器上的文件夹(在这种情况下,一旦保存类,MANIFEST.MF 就会刷新) .java 文件)
如您所见,您必须始终复制生成的 MANIFEST.MF 以确保 Import-Package 部分也被刷新。
如果您可以通过 ssh 或 telnet 连接到您的服务器(例如使用 felix-osgi-console 或 equinox-console),您可以编写一个简短的 shell 脚本(或 Windows 中的 cmd)来执行此操作。
If you use the bundleContext.installBundle(String location) to install your bundle you can define a folder on your server where the jar is unpackaged. After that you can copy only that class to the server folder and call the update command on that bundle.
If you use Eclipse with m2e and maven-bundle-plugin you can simply sinchronize the target/classes directory to the folder on your server right after saving the class (as in that case MANIFEST.MF is refreshed as well as soon as you save your .java file)
As you can see you have to copy the generated MANIFEST.MF always to be sure that Import-Package section is refreshed as well.
You can write a short shell script (or cmd in windows) to do this if you can connect to your server via ssh or telnet (e.g. using felix-osgi-console or equinox-console).