felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From KingSaladin <jelra...@gmail.com>
Subject Unable to reach Groovy script Engine from an other OSGI bundle
Date Tue, 13 Oct 2015 10:49:05 GMT
I am trying to test groovy scripting from withing my first new bundle
deployed under Felix.

I installed successfully the groovy-all.jar as a bundle via the GOGO shell

g! lb
   ID|State      |Level|Name
  * 33|Active     |    1|Groovy Runtime (2.1.6)*

Than i created a simple bundle ( just an Activator)  whose main testing
purpose is to  list the bundles that embed a ScriptEngineFactory
implementation and display few information about them ( symbolic name,
version and  last modification time/date). *Than at the end fetch the grovvy
script engine and test a simple groovy script.*

My Bundle works fine till it reaches the groovy fetching part where it fails
to find the groovy script engine and obviously fails to evaluate the simple
groovy command:

 g! install
Bundle ID: 44
g! start 44
Starting bundle MyBundle
  i found 23  bundles
  Here is an other scriptengines i found  groovy-all version 2.1.6 last
modified Sat Nov 22 09:02:35 CET 47721
  Here is an other scriptengines i found  org.jruby.jruby version 1.7.4 last
modified Sun Nov 23 06:04:10 CET 47721
*groovy not found Sorry!*

Here is the Bundle only class, its Activator:

package com.king.osgi.samples.myBundle;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.util.tracker.BundleTrackerCustomizer;

import java.util.Calendar;
import javax.script.ScriptEngineManager;
import javax.script.*;

public class Activator implements BundleActivator, ServiceListener,
BundleTrackerCustomizer {
	private static final String ENGINE_FACTORY_SERVICE = "META-INF/services/" +
	private ScriptEngineManager scriptEngineManager;
	public void start(BundleContext context) throws Exception {
		// TODO Auto-generated method stub
		System.out.println("Starting bundle: MyBundle");
		// rfetching available actibe bundle that embed a ScriptEngineFactory
		Bundle[] bundles = context.getBundles();
		System.out.println(" i found " + bundles.length + "  bundles");
		for (Bundle bundle : bundles) {
			if (bundle.getState() == Bundle.ACTIVE &&
bundle.getEntry(ENGINE_FACTORY_SERVICE) != null) {
				long modified = bundle.getLastModified();
				Calendar cal = Calendar.getInstance();
				cal.setTimeInMillis(modified * 1000);
				System.out.println("  Here is an other scriptengine i found  " +
bundle.getSymbolicName() + " version "
						+ bundle.getVersion() + " last modified " + cal.getTime());


		// test some groovy script here
		String engineNameOrExtension = "groovy";
		ScriptEngineManager mgr = new ScriptEngineManager(); // also tried with
new ScriptEngineManager(Thread.currentThread().getContextClassLoader());
		ScriptEngine engine = mgr.getEngineByExtension(engineNameOrExtension);
		//engine = mgr.getEngineByName(engineNameOrExtension); tried with engine
name too but no success!
		if ( engine != null){
		System.out.println(engineNameOrExtension +" not found Sorry!" );	
		// test some jruby or anything else here


	public void stop(BundleContext context) throws Exception {
		// TODO Auto-generated method stub
		System.out.println("Stopping bundle MyBundle");

	public void serviceChanged(ServiceEvent event) {
		// TODO Auto-generated method stub
		System.out.println("Service is changing...");

	public Object addingBundle(Bundle bundle, BundleEvent event) {
		// TODO Auto-generated method stub
		return null;

	public void modifiedBundle(Bundle bundle, BundleEvent event, Object object)
		// TODO Auto-generated method stub
		System.out.println("Service is modified...");

	public void removedBundle(Bundle bundle, BundleEvent event, Object object)
		// TODO Auto-generated method stub
		System.out.println("Service is removed ...");


Here is also the pom.xml file ( just in case):

<project xmlns="http://maven.apache.org/POM/4.0.0"

  <name>King's first OSGI bundle under Felix</name>
  <description>King's first OSGI bundle under Felix</description>

<Import-Package>com.king.osgi.samples.myBundle.*,org.osgi.framework.* ,
org.osgi.util.* , javax.script.*</Import-Package>


Is this a classloading issue? if yes how can i fix this? If not can anyone
please point to the mistake i did ?


View this message in context: http://apache-felix.18485.x6.nabble.com/Unable-to-reach-Groovy-script-Engine-from-an-other-OSGI-bundle-tp5015137.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.

To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org

View raw message