【发布时间】:2014-01-23 02:54:39
【问题描述】:
我想创建一个简单的 osgi 包来运行 ruby 源文件,所以我使用 jruby-complete 。这里是代码示例
运行 jruby 文件的包
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());
}
}
}
使用上述包的包
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
}
}
使用 maven 构建 osgi 包的 POM 文件
<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>
步骤:
- 使用 osgi 启动 felix
- 启动 jruby-complete(此 jar 文件使用 pax-wrap 将其打包为 osgi 包:https://ops4j1.jira.com/wiki/display/paxurl/Wrap+Protocol)
-
开始我的捆绑 现在它引发了一个错误:
(LoadError) 没有要加载的文件 -- jruby/jruby.rb
当然,jruby/jruby.rb 包含在 jruby-complete.jar 中,而不是在我的示例包中
那么,我该怎么办??
【问题讨论】: