Java Osgi swing嵌入式应用程序
我是osgi的新手,我正在通过互联网学习它的基础。昨天我从www.eclipsezone.com/files/jsig/code.zip下载了一些代码。我可以使用ApacheFelix运行所有应用程序,键入java-jar bin/felix.jar。 但是,我尝试使用以下代码将felix嵌入到project Explorer中:Java Osgi swing嵌入式应用程序,java,swing,osgi,Java,Swing,Osgi,我是osgi的新手,我正在通过互联网学习它的基础。昨天我从www.eclipsezone.com/files/jsig/code.zip下载了一些代码。我可以使用ApacheFelix运行所有应用程序,键入java-jar bin/felix.jar。 但是,我尝试使用以下代码将felix嵌入到project Explorer中: package org.example.osgi.explorer.internal; import java.util.HashMap; import java.u
package org.example.osgi.explorer.internal;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.util.FelixConstants;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
public class Main {
public static void main(String[] argv) throws Exception {
Map<String, Object> map = new HashMap<>();
map.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"some.module.i.dont.know; version=1.0.0");
ExplorerActivator activator = new ExplorerActivator();
List<Object> list = new LinkedList<>();
list.add(activator);
map.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
Felix f = new Felix(map);
System.out.println("starting OSGI...");
f.start();
String home_dir="file:/G:/code2/JSIG_OSGi/";
Bundle b = f.getBundleContext().installBundle(home_dir+"projects/Explorer/dist/Explorer.jar");
Bundle b2 = f.getBundleContext().installBundle(home_dir+"projects/PropertiesAction/dist/PropertiesAction.jar");
// Bundle b3 = f.getBundleContext().installBundle(home_dir+"projects/ViewAction/dist/ViewAction.jar");
// Bundle b4 = f.getBundleContext().installBundle(home_dir+"bundles/org.apache.fop_0.20.5.jar");
// Bundle b5 = f.getBundleContext().installBundle(home_dir+"bundles/org.apache.fop_0.93.0.jar");
// Bundle b6 = f.getBundleContext().installBundle(home_dir+"projects/Fop20RenderAction/dist/Fop20RenderAction.jar");
// Bundle b7 = f.getBundleContext().installBundle(home_dir+"projects/Fop93RenderAction/dist/Fop93RenderAction.jar");
// String bName = b.getLocation();
//
// System.out.println("starting bundle " + bName);
b.start();
b2.start();
}
}
发生此异常的原因。如何解决此问题
编辑:
是的,它实现了!
代码:
编辑:以下代码已生效:
FrameworkFactory ff = new FrameworkFactory ();
Map<String,Object> config = new HashMap<String,Object>();
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,"packages needed,more packages needed");
config.put(Constants.FRAMEWORK_STORAGE_CLEAN, "true");
Framework fwk = ff.newFramework(config);
fwk.start();
BundleContext context = fwk.getBundleContext();
String home_dir="file:/G:/code2/JSIG_OSGi/";
Bundle bundle = context.installBundle(home_dir+"projects/Explorer/dist/Explorer.jar");
bundle.start();
Bundle bundle2 = context.installBundle(home_dir+
"projects/PropertiesAction/dist/PropertiesAction.jar");
bundle2.start();
//ExplorerActivator.isopened will be false if frame disposed.
if(ExplorerActivator.isopened) {
bundle.stop();
bundle2.stop();
bundle.uninstall();
bundle2.uninstall();
fwk.stop();
fwk.waitForStop(1000);
}
FrameworkFactory ff=newframeworkfactory();
Map config=newhashmap();
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,“需要包,需要更多包”);
config.put(Constants.FRAMEWORK_STORAGE_CLEAN,“true”);
Framework fwk=ff.newFramework(配置);
fwk.start();
BundleContext=fwk.getBundleContext();
字符串home_dir=“file:/G:/code2/JSIG_OSGi/”;
Bundle Bundle=context.installBundle(home_dir+“projects/Explorer/dist/Explorer.jar”);
bundle.start();
Bundle bundle2=context.installBundle(主目录)+
“projects/PropertiesAction/dist/PropertiesAction.jar”);
bundle2.start();
//如果处理了帧,则ExplorerActivator.isopend将为false。
if(ExplorerActivator.isopened){
bundle.stop();
bundle2.stop();
bundle.uninstall();
bundle2.uninstall();
fwk.stop();
waitForStop公园(1000);
}
显而易见的答案是,您正在将属性操作的一个实例强制转换到接口org.example.osgi.explorer.FileSelectionListener
,但它实际上并没有实现该接口
如果您认为它确实实现了该接口,那么您需要提供更多信息。根据例外情况,您是对的。但是为什么在嵌入时会发生这种异常呢?我可以通过键入java-jarbin/felix.jar来运行这个包。
package org.example.osgi.propertiesaction;
import java.awt.Component;
import java.awt.Container;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import org.example.osgi.explorer.FileSelectionListener;
public class PropertiesAction extends AbstractAction implements FileSelectionListener {
private static final File[] EMPTY = new File[0];
private File[] selection;
public PropertiesAction() {
super("Properties");
setEnabled(false);
}
public void actionPerformed(ActionEvent event) {
Frame frame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, (Component) event.getSource());
FilePropertiesDialog dialog = new FilePropertiesDialog(selection, frame, true);
dialog.setVisible(true);
}
public void selectionChanged(File[] selection) {
this.selection = (selection == null) ? EMPTY : selection;
setEnabled(selection != null && selection.length > 0);
}
}
FrameworkFactory ff = new FrameworkFactory ();
Map<String,Object> config = new HashMap<String,Object>();
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,"packages needed,more packages needed");
config.put(Constants.FRAMEWORK_STORAGE_CLEAN, "true");
Framework fwk = ff.newFramework(config);
fwk.start();
BundleContext context = fwk.getBundleContext();
String home_dir="file:/G:/code2/JSIG_OSGi/";
Bundle bundle = context.installBundle(home_dir+"projects/Explorer/dist/Explorer.jar");
bundle.start();
Bundle bundle2 = context.installBundle(home_dir+
"projects/PropertiesAction/dist/PropertiesAction.jar");
bundle2.start();
//ExplorerActivator.isopened will be false if frame disposed.
if(ExplorerActivator.isopened) {
bundle.stop();
bundle2.stop();
bundle.uninstall();
bundle2.uninstall();
fwk.stop();
fwk.waitForStop(1000);
}