0

My bundle contains a script(.bat and .sh) in the Resources folder. It is necessary to execute this script inside the bundle.

How could I achieve this in the OSGi world ? Example would be a.w.e.s.o.m.e

  • can you run your scripts using a normal java program ? what is the error when running inside a service class ? – Cristiano Feb 06 '14 at 12:38

2 Answers2

0

I assume you script needs to do something when bundle becomes Active? In a bundle you can create an Activator (implement the BundleActivator interface) and have it run the scripts.

I'm not sure what your scripts do but personally I would not use scripts and try to do things differently.

codesalsa
  • 882
  • 5
  • 18
  • Yes, yes surely it will run once it becomes active(in fact it would run when the Service provided by this bundle get's invoked. This service will need to run the script. (The problem I find is that I can't run the script inside the bundle) – Sunny M0nkey Feb 06 '14 at 09:17
0

To execute a script, you can use Runtime.exec(..) to launch a shell (sh, bash, etc..). These shells can execute a script that is either provided as a file, or read from standard input. The latter option can be leveraged here. Runtime.exec(..) returns a Process object, and you can obtain its input and output streams. Fetch the resource from your bundle as described here How do I access a file inside an OSGi bundle? and pass that data to your stream.

Community
  • 1
  • 1
Marcel Offermans
  • 3,313
  • 1
  • 15
  • 23