在看深入理解OSGI:Equinox原理第五章,按照书上说明,在eclipse的plugins目录下执行命令
java -jar org.eclipse.osgi_version.jar -console
本来控制台应该出现
osgi>
但是控制台没有反应,后面发现当前目录下多了一个configuration文件夹,其中有log文件
!SESSION 2018-10-30 22:55:31.170 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_172
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments: -console
!ENTRY org.eclipse.osgi 4 0 2018-10-30 22:55:31.397
!MESSAGE Could not find bundle: org.eclipse.equinox.console
!STACK 0
org.osgi.framework.BundleException: Could not find bundle: org.eclipse.equinox.console
at org.eclipse.core.runtime.internal.adaptor.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:58)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:331)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:231)
at org.eclipse.core.runtime.adaptor.EclipseStarter.main(EclipseStarter.java:208)
!ENTRY org.eclipse.osgi 4 0 2018-10-30 22:55:31.404
!MESSAGE Application error
!STACK 1
java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:78)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at org.eclipse.core.runtime.adaptor.EclipseStarter.main(EclipseStarter.java:208)
发现遇到相同情况
解决方案地址
得知解决方案
是创建configuration/config.ini文件,并添加如下内容
osgi.bundles=file\:org.eclipse.equinox.console_1.0.0.v20111215-1210.jar@start,file:\org.apache.felix.gogo.runtime_0.8.0.v201108120515.jar@start,file:\org.apache.felix.gogo.shell_0.8.0.v201110170705.jar@start
注意:需要内容中的版本,需要根据plugins目录下你自己的jar版本去做替换。
原因是:在equinox的新版本中,内置的OSGI shell被felix gogo shell所替代,所以要运行则需要在上述的配置文件中,添加所需要的4个bundle。
我使用的eclipse版本为:Version: Luna Service Release 2 (4.4.2)