OSGi console not shown in command line

痞子三分冷 提交于 2020-01-14 04:47:04

问题


I'm trying to get an OSGi example application working, but I'm running into trouble while starting OSGi from the command line.

Note that I don't want to run the bundle in the Eclipse OSGi environment. This works fine.


First, I created the example bundle. Afterwards, I tried to run the the application in the command line. To do so, I run the OSGi jar as stated in the above-mentioned article, official instructions and a related question:

$ cd
$ cp /usr/local/eclipse/plugins/org.eclipse.osgi_3.8.2.v20130124-134944.jar
     org.eclipse.osgi.jar
$ java -jar org.eclipse.osgi.jar -console

Now, OSGi seems to run, but the console is not shown.


According to the above-mentioned article (see Section 4.2) and a related question with solution, the following additional packages are required:

  • org.eclipse.equinox.console
  • org.apache.felix.gogo.command
  • org.apache.felix.gogo.runtime
  • org.apache.felix.gogo.shell

Are they missing? If yes, how do I link them?


My question: How can I run OSGi with console in the command line?

Thanks for any help!

EDIT 1: $ eclipse -console -noExit and closing the IDE works as a workaround :-) sadly, IDE bundles are loaded this way as well.


回答1:


Here is a generic command to have it working with Equinox implementation on both Unix and Windows systems.

Tested with an install of Eclipse 2018-12, however it should work with other versions as well.

Go to the plugin directory

Unix, bash:

java -Dosgi.bundles=\
$(ls -1 org.apache.felix.gogo.shell_*.jar)@start,\
$(ls -1 org.apache.felix.gogo.command_*.jar)@start,\
$(ls -1 org.apache.felix.gogo.runtime_*.jar)@start,\
$(ls -1 org.eclipse.equinox.console_*.jar)@start\
 -jar $(ls -1 org.eclipse.osgi_*.jar) -console

Windows, powershell (works in console mode only):

java ('-Dosgi.bundles='+((`
"$(ls org.apache.felix.gogo.shell_*.jar | select -ExpandProperty Name)`@start",`
"$(ls org.apache.felix.gogo.command_*.jar | select -ExpandProperty Name)`@start",`
"$(ls org.apache.felix.gogo.runtime_*.jar | select -ExpandProperty Name)`@start",`
"$(ls org.eclipse.equinox.console_*.jar | select -ExpandProperty Name)`@start"`
) -join ',')) '-jar' "$(ls org.eclipse.osgi_*.jar | select -ExpandProperty Name)" '-console'

Windows, powershell (works with ISE as well):

Start-Process 'java' -ArgumentList `
(('-Dosgi.bundles=',`
"$(ls org.apache.felix.gogo.shell_*.jar | select -ExpandProperty Name)`@start,",`
"$(ls org.apache.felix.gogo.command_*.jar | select -ExpandProperty Name)`@start,",`
"$(ls org.apache.felix.gogo.runtime_*.jar | select -ExpandProperty Name)`@start,",`
"$(ls org.eclipse.equinox.console_*.jar | select -ExpandProperty Name)`@start",`
" -jar $(ls org.eclipse.osgi_*.jar | select -ExpandProperty Name) -console"
) -join '')

Link to the eclipse bug:
Bug 371101 - Equinox console doesn't start




回答2:


A workaround is not to run Equinox implementation of OSGi Apache Felix Framework as stated in the mentioned related question:

  • Download the framework.
  • Unzip the framework
  • Run the following command:

$ java -jar bin/felix.jar


Anyway, this seems to be a workaround to me and I'm still interested in how to use the Equinox framework from the command line.



来源:https://stackoverflow.com/questions/19079830/osgi-console-not-shown-in-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!