本文对应书本5.1.3的内容
书本中通过CVS下载的源码
但是笔者实践的时候发现无法下载...地址已经失效了(也许是笔者的失误输错地址所致)
可以用git下载
地址是:
http://git.eclipse.org/c/equinox
进入需要下载的组件的页面 在最下面有git clone的地址
http://git.eclipse.org/c/equinox/rt.equinox.framework.git/ 写道
Clone
git://git.eclipse.org/gitroot/equinox/rt.equinox.framework.git
ssh://git.eclipse.org/gitroot/equinox/rt.equinox.framework.git
http://git.eclipse.org/gitroot/equinox/rt.equinox.framework.git
git://git.eclipse.org/gitroot/equinox/rt.equinox.framework.git
ssh://git.eclipse.org/gitroot/equinox/rt.equinox.framework.git
http://git.eclipse.org/gitroot/equinox/rt.equinox.framework.git
在eclipse中下载很简单 打开git仓库的面板 输入地址即可
选择需要的导入就可以了
接下来配置run configuration
和书中一样这里截图略过:
接下来是dev.properties文件和conf.ini文件 如下:
- BundleHelloworld=bin
- org.eclipse.osgi=bin
- @ignoredot@=true
conf.ini:
- #和书中相比多了很多其他的bundle 这些是启动console必需的
- osgi.bundles=reference:file\:G:/osgi_workbench/test/BundleHelloworld@start,reference:file\:E:/eclipseForEE/osgi_test/eclipse/plugins/org.apache.felix.gogo.command_0.10.0.v201209301215.jar@start,reference:file\:E:/eclipseForEE/osgi_test/eclipse/plugins/org.apache.felix.gogo.runtime_0.10.0.v201209301036.jar@start,reference:file\:E:/eclipseForEE/osgi_test/eclipse/plugins/org.apache.felix.gogo.shell_0.10.0.v201212101605.jar@start,reference:file\:E:/eclipseForEE/osgi_test/eclipse/plugins/org.eclipse.equinox.console_1.0.100.v20130429-0953.jar@start
- osgi.bundles.defaultStartLevel=4
- osgi.framework=file:H:/repository/git/rt.equinox.framework/rt.equinox.framework/bundles/org.eclipse.osgi
- #osgi.framework=file/:E:/eclipseForEE/osgi_test/eclipse/plugins/org.eclipse.osgi_3.9.1.v20130814-1242.jar
- eclipse.ignoreApp=true
- osgi.noShutdown=true
- osgi.console=
有关以上比书本上多的那几个jar 看:
可以直接用eclipse的plugins文件夹下的
没有那几个jar BundleHelloworld可以运行 但不会出现 osgi>
并且会有错误信息 如下:
log 写道
!SESSION 2013-12-23 13:33:04.949 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_40
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=zh_CN
Command-line arguments: -dev file:E:/eclipseForEE/osgi_test/config/dev.properties
!ENTRY org.eclipse.osgi 4 0 2013-12-23 13:33:05.347
!MESSAGE Could not find bundle: false
!STACK 0
org.osgi.framework.BundleException: Could not find bundle: false
at org.eclipse.core.runtime.internal.adaptor.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:58)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:323)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:222)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
eclipse.buildId=unknown
java.version=1.7.0_40
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=zh_CN
Command-line arguments: -dev file:E:/eclipseForEE/osgi_test/config/dev.properties
!ENTRY org.eclipse.osgi 4 0 2013-12-23 13:33:05.347
!MESSAGE Could not find bundle: false
!STACK 0
org.osgi.framework.BundleException: Could not find bundle: false
at org.eclipse.core.runtime.internal.adaptor.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:58)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:323)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:222)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
注意bundle中的文件前应该有 reference:file: 不然会提示找不到
在以上新建的java application中点run 会出现以下信息就代表运行成功: