简体   繁体   English

从OSGi捆绑包中启动类的主要方法

[英]Start a main method of a class from within an OSGi bundle

I have a jar file, A.jar, that contains, among various library functions, a class with a main method, MainClass . 我有一个jar文件A.jar,其中包含各种库函数以及一个具有main方法MainClass This jar file is deployed by wrapping it into an OSGi bundle, B.jar, so that the library functions are available to other plugins within the OSGi container, as specified in B.jar's MANIFEST.MF. 通过将jar文件包装到OSGi捆绑软件B.jar中进行部署,以便库功能可用于OSGi容器中的其他插件,如B.jar的MANIFEST.MF中所指定。

I also want to be able to launch the MainClass.main method contained in A.jar in a separate process, outside OSGi, but all I have available on the file system is B.jar. 我还希望能够在OSGi之外的单独进程中启动MainClass.main包含的MainClass.main方法,但是文件系统上可用的全部是B.jar。 So, for example, 因此,例如

java -cp B.jar MainClass

fails with 失败于

Error: Could not find or load main class MainClass

whereas

java -cp A.jar MainClass

works just fine on my desktop, before A.jar is wrapped up in B.jar. 在将A.jar包装在B.jar中之前,在我的桌面上可以正常工作。

Is there any way to run MainClass.main directly from B.jar? 有没有办法运行MainClass.main直接从B.jar?

It is not clear but I assume that B.jar contains A.jar as an entry. 尚不清楚,但我认为B.jar包含A.jar作为条目。 So A.jar is just a resource in B.jar. 因此,A.jar只是B.jar中的资源。 In order to run the MainClass in A.jar from B.jar, you will need to write a new main for B.jar that will create a ClassLoader for the A.jar resource and then load MainClass class and call its main method. 为了从B.jar在A.jar中运行MainClass,您将需要为B.jar编写一个新的main,它将为A.jar资源创建一个ClassLoader,然后加载MainClass类并调用其main方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM