[英]How can I go about using a **CSS** resource file in one OSGi bundle from another OSGi bundle
我的项目目录结构(在Eclipse中):
MyProjectContainingCSS/
src/ --> "source directory" on Eclipse's classpath/buildpath
com.me.myapp
style.css
MyProjectInheritingCSS/
src/ --> "source directory" on Eclipse's classpath/buildpath
com.me.myapp
StyleImpl.java
我想包含在OSGi包CSS文件style.css中使用MyProjectContainingCSS
在其他OSGi包MyProjectContainingCSS
在类StyleImpl.java
,
就像是:
public class StyleImpl {
public static void main(String[] args) {
css = this.getClass().getResource("/com/me/myapp/style.css").toExternalForm();
scene.getStylesheets().add(css);
}
}
如何在另一个OSGi捆绑包中的一个OSGi捆绑包中使用CSS资源文件?
谢谢大家。
更新
bnd.bnd文件
Bundle-Version: 0.0.0.${tstamp}
-buildpath: \
../cnf/plugins/org.apache.felix.dependencymanager.annotation-3.2.0.jar;version=file,\
org.apache.felix.dependencymanager,\
osgi.core,\
launcher;version=latest,\
libs/commons-io-2.4.jar;version=file
Private-Package: ui.impl
Export-Package: ui
Import-Package: *
运行描述符
-runfw: org.apache.felix.framework;version='[4,5)'
-runee: JavaSE-1.8
-runsystemcapabilities: ${native_capability}
-resolve.effective: active;skip:="osgi.service"
-runbundles: \
org.apache.felix.dependencymanager,\
org.apache.felix.dependencymanager.runtime,\
org.apache.felix.dependencymanager.shell,\
org.apache.felix.metatype,\
org.apache.felix.eventadmin,\
org.apache.felix.configadmin,\
org.apache.felix.log,\
org.apache.felix.gogo.command,\
org.apache.felix.gogo.runtime,\
org.apache.felix.gogo.shell,\
launcher;version=latest,\
ui;version=latest,\
mainscreen;version=latest
-runsystempackages: javafx.application,javafx.scene,javafx.stage,javafx.scene.layout,javafx.event,javafx.collections,javafx.scene.control,javafx.scene.paint,javafx.scene.shape
要从您自己的捆绑包中获取文件,您可以执行以下操作:
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
Enumeration<URL> resources = bundle.getResources("/com/me/myapp/style.css");
if (resources != null) {
URL myCSS = resources.nextElement();
}
如果可以找到其他OSGi捆绑对象,则可以执行相同操作。 我会尝试这样的事情:
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
Bundle[] bArray = bundle.getBundleContext().getBundles();
Bundle cssBundle = null;
for (Bundle b : bArray){
if(b.getSymbolicName().equals("com.me.myapp")) {
cssBundle = b;
break;
}
}
Enumeration<URL> resources = cssBundle.getResources("/com/me/myapp/style.css");
if (resources != null) {
URL myCSS = resources.nextElement();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.