I want to create an simple osgi bundle to run ruby source file , so i using jruby-complete .Here is code example
A bundle which run jruby file
package activator;
import org.jruby.embed.ScriptingContainer;
public class Main {
public void runRubySource(String[] args) {
try {
System.out.println("JRUBYYYYYYYYYYYYYYYYYYYYYYYYy");
ScriptingContainer container = new ScriptingContainer();
container.setArgv(args);
container.runScriptlet("require 'ruby/test.rb'");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
A bundle which using above bundle
package activator;
import activator.Main;
import org.jruby.embed.ScriptingContainer;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Test implements Activator{
@Override
public void start(BundleContext context) throws Exception {
// TODO Auto-generated method stub
Main m = new Main();
String[] args = {"-c","C:\\fileconfig.conf"};
m.runRubySource(args );
}
@Override
public void stop(BundleContext context) throws Exception {
// TODO Auto-generated method stub
}
}
POM file for osgi bundle build using maven
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.insight</groupId>
<artifactId>jruby</artifactId>
<packaging>bundle</packaging>
<name>JrubyDemo</name>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.0.1</version>
<extensions>true</extensions>
<configuration>
<Embed-Transitive>true</Embed-Transitive>
<Export-Package>*</Export-Package>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Steps :
- Start felix with osgi
- Start jruby-complete (this jar file wrap using pax-wrap to make it as a osgi bundle: https://ops4j1.jira.com/wiki/display/paxurl/Wrap+Protocol )
Start my bundle Now it raise an error:
(LoadError) no such file to load -- jruby/jruby.rb
Certainly, jruby/jruby.rb is contained in jruby-complete.jar ,not in my example bundle
So, what i have to do ??