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 console: g! lb START LEVEL 1 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 file:/C:/myProjects/MyOSGIBundles/target/myBundle-1.0.1-SNAPSHOT.jar 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!* g! 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.*; @SuppressWarnings("restriction") public class Activator implements BundleActivator, ServiceListener, BundleTrackerCustomizer { @SuppressWarnings("restriction") private static final String ENGINE_FACTORY_SERVICE = "META-INF/services/" + ScriptEngineFactory.class.getName(); private ScriptEngineManager scriptEngineManager; @SuppressWarnings("restriction") 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(engine.eval("(1..10).sum()")); }else{ 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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.king.osgi.samples</groupId> <artifactId>myBundle</artifactId> <packaging>bundle</packaging> <version>1.0.1-SNAPSHOT</version> <name>King's first OSGI bundle under Felix</name> <description>King's first OSGI bundle under Felix</description> <properties> </properties> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.5.3</version> <extensions>true</extensions> <configuration> <instructions> <Bundle-Category>osgi</Bundle-Category> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> <Import-Package>com.king.osgi.samples.myBundle.*,org.osgi.framework.* , org.osgi.util.* , javax.script.*</Import-Package> <Bundle-Activator>com.king.osgi.samples.myBundle.Activator</Bundle-Activator> </instructions> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> <version>4.2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> <version>4.2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>1.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.webconsole</artifactId> <version>3.1.8</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20070829</version> <scope>provided</scope> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> <version>4.10</version> </dependency> <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.6.0</version> <scope>test</scope> </dependency> </dependencies> </project> Is this a classloading issue? if yes how can i fix this? If not can anyone please point to the mistake i did ? Regards, King -- 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-unsubscr...@felix.apache.org For additional commands, e-mail: users-h...@felix.apache.org