[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [concierge-dev] Concierge embedded in JavaFX application
|
From looking at your code I could imagine that our use of Constants.FRAMEWORK_SYSTEMPACKAGES is causing the problem. I would recommend to better use Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA instead because otherwise you are overwriting the defaults and that could cause the resolver to fail because nothing exports org.osgi.framework anymore. The "EXTRA" version keeps the defaults and allows you to add additional packages to it which is what you really want.
--Jan.
Ladislav Török ---12/03/2014 01:16:33 AM---I'm trying to replace Equinox to Concierge in project Dukepad - see: https://wiki.openjdk.java.net/d
From: Ladislav Török <ltorokrl@xxxxxxxxx>
To: Concierge developer discussions <concierge-dev@xxxxxxxxxxx>
Date: 12/03/2014 01:16 AM
Subject: Re: [concierge-dev] Concierge embedded in JavaFX application
Sent by: concierge-dev-bounces@xxxxxxxxxxx
I'm trying to replace Equinox to Concierge in project Dukepad - see: https://wiki.openjdk.java.net/display/OpenJFX/DukePad
I am using class ' StarterApplication' as my main JavaFX application:
package com.javafx.experiments.dukepad.starter;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.DepthTest;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.eclipse.core.runtime.adaptor.EclipseStarter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import java.io.File;
import java.net.MalformedURLException;
import java.util.*;
import org.eclipse.concierge.Factory;
import org.osgi.framework.Constants;
import org.osgi.framework.launch.Framework;
/**
* Starter for DukePad platform
*/
public class StarterApplication extends Application {
private Framework framework;
private Stage primaryStage;
private Scene scene;
private final LinkedList<Runnable> loadingTasks = new LinkedList<>();
private final List<Bundle> bundles = new ArrayList<>();
public void start(Stage primaryStage) {
// create main window and show splash screen
this.primaryStage = primaryStage;
ImageView bootScreen = new ImageView(new Image(StarterApplication.class.getResource("/Duke-Startup.jpg").toExternalForm(),false));
Text loadingText = new Text("Loading...");
loadingText.setFont(Font.font("System",24));
loadingText.setFill(Color.rgb(255, 255, 255, 0.8));
loadingText.setX(30);
loadingText.setY(50);
scene = new Scene(new Group(bootScreen,loadingText), 1300, 800);
// scene.setFill(Color.BLACK);
// scene.setFill(Color.TRANSPARENT);
scene.setFill(Color.RED);
// primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(scene);
primaryStage.show();
// boot OSGi in own thread
Platform.runLater(() -> startOSGi(loadingText));
}
private void startOSGi(final Text loadingText) {
try {
// CONFIGURE OSGI
//String[] equinoxArgs = {"-clean",/*"-consoleLog",*/"-console","-dev","bin"};
Map<String,String> initialProperties = new HashMap<>();
// initialProperties.put("osgi.console.enable.builtin", "true");
// initialProperties.put("osgi.parentClassloader","ext");
// initialProperties.put("org.osgi.framework.system.packages","sun.misc,java,javax,javax.net.ssl,javax.security.cert,javax.naming,javax.naming.directory,javax.security.auth,javax.security.auth.x500");
// EclipseStarter.setInitialProperties(initialProperties);
initialProperties.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_BOOT);
initialProperties.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "sun.misc,java,javax,javax.net.ssl,javax.security.cert,javax.naming,javax.naming.directory,javax.security.auth,javax.security.auth.x500");
// START OSGI
//final BundleContext context = EclipseStarter.startup(equinoxArgs, null);
Factory factory = new Factory();
framework = factory.newFramework(initialProperties);
framework.init();
framework.start();
final BundleContext context = framework.getBundleContext();
// REGISTER SCENE AND STAGE AS SERVICES
context.registerService(Scene.class,scene, null);
context.registerService(Stage.class,primaryStage, null);
// Create tasks to install all jar bundles in bundles directory
File bundleDir = new File("bundles");
if (bundleDir.exists()) {
File[] bundleJars = bundleDir.listFiles();
if (bundleJars != null) {
// load app modules
for (final File file: bundleJars) {
if (file.getName().endsWith(".jar")) {
loadingTasks.add(() -> {
final String name = file.getName().substring(0,file.getName().lastIndexOf('.'));
loadingText.setText("Loading " + name);
System.out.println("Loading " + name);
try {
bundles.add(context.installBundle(file.toURI().toURL().toExternalForm()));
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
}
}
// Create task to start all bundles
loadingTasks.add(() -> {
for (Bundle b: bundles) {
loadingTasks.push(() -> {
loadingText.setText("Starting " + b.getSymbolicName());
System.out.println("Starting " + b.getSymbolicName());
try {
b.start();
} catch (BundleException e) {
e.printStackTrace();
}
});
}
});
// Create task to install and start all bundles in apps directory
File appDir = new File("D:\\applications");
if (appDir.exists()) {
File[] appJars = appDir.listFiles();
if (appJars != null) {
// sort alphabetical
Arrays.sort(appJars,new Comparator<File>() {
@Override public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
// load app modules
for (File file: appJars) {
if (file.getName().endsWith(".jar")) {
loadingTasks.add(() -> {
final String name = file.getName().substring(0,file.getName().lastIndexOf('.'));
loadingText.setText("Loading " + name);
System.out.println("Loading " + name);
try {
Bundle bundle = context.installBundle(file.toURI().toURL().toExternalForm());
bundle.start();
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
}
}
} catch(Exception e) {
e.printStackTrace();
}
// start executing all the tasks we have queued up
runNextStartupTask();
}
/**
* Execute each task from list in order in separate platform.runLater(). This allows FX to draw the screen
* between tasks.
*/
private void runNextStartupTask() {
if (loadingTasks.isEmpty()) return;
final Runnable task = loadingTasks.pop();
Platform.runLater(new Runnable() {
@Override public void run() {
task.run();
runNextStartupTask();
}
});
}
@Override public void stop() throws Exception {
System.out.println("StarterApplication.stop");
//EclipseStarter.shutdown();
framework.stop();
}
public static void main(String[] args) {
// System.setProperty("org.osgi.framework.system.packages.extra","javafx.application");
launch(args);
}
}
and class 'Activator' as bundle:
package sk.ltorok.xbundle;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
System.out.println("Hello from my firstbundle...");
// Get Scene Service
Scene scene = context.getService(context.getServiceReference(Scene.class));
// System.out.println(scene.toString());
// System.out.println(scene.getFill().toString());
// scene.setFill(Color.YELLOW);
}
@Override
public void stop(BundleContext context) throws Exception {
System.out.println("Bye from my firstbundle...");
}
}
MANIFEST.MF file for bundle above is:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.2
Created-By: 1.8.0_40-ea-b15 (Oracle Corporation)
Bundle-Version: 1.0.0
Bundle-Name: sk.ltorok.xbundle
Bundle-Activator: sk.ltorok.xbundle.Activator
Bundle-ManifestVersion: 2
Bundle-SymbolicName: sk.ltorok.xbundle
Import-Package: org.osgi.framework
Require-Bundle: sk.ltorok.xbundle
after run 'StarterApplication' I get Exception:
---------------------------------------------------------
Concierge OSGi 5.0.0.alpha on Windows 7 6.1 starting ... (default) startlevel=3
---------------------------------------------------------
---------------------------------------------------------
Framework started in 0.003 seconds.
---------------------------------------------------------
Loading XBundle
org.osgi.framework.BundleException: Resolution failed [BundleRequirement{Import-Package org.osgi.framework}]
at org.eclipse.concierge.Concierge.resolve(Concierge.java:2435)
at org.eclipse.concierge.BundleImpl$Revision.resolve(BundleImpl.java:1816)
at org.eclipse.concierge.BundleImpl.activate(BundleImpl.java:453)
at org.eclipse.concierge.BundleImpl.start(BundleImpl.java:427)
at org.eclipse.concierge.BundleImpl.start(BundleImpl.java:367)
at com.javafx.experiments.dukepad.starter.StarterApplication.lambda$startOSGi$27(StarterApplication.java:167)
at com.javafx.experiments.dukepad.starter.StarterApplication$$Lambda$101/1330056022.run(Unknown Source)
at com.javafx.experiments.dukepad.starter.StarterApplication$2.run(StarterApplication.java:193)
at com.sun.javafx.application.PlatformImpl.lambda$null$169(PlatformImpl.java:295) at com.sun.javafx.application.PlatformImpl.lambda$null$169(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/540370836.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$170(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1232367853.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$144(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/1161082381.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
BUILD STOPPED (total time: 1 minute 54 seconds)
When I replace line initialProperties.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_BOOT); to initialProperties.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_EXT);
result is the same.
Thanks for any help.
2014-12-02 21:03 GMT+01:00 Jan S Rellermeyer <rellermeyer@xxxxxxxxxx>:
Hi Ladislav,
Concierge in JavaFX is an interesting problem and I have not tried that myself, nor am I aware of anybody else who did.
Would you be able to share some basic code/test case that leads to the failure that you describe? That would help us to look into the problem.
--Jan.
Ladislav Török ---12/02/2014 02:02:12 PM---I have a problem. I am embedding (hosting) Concierge in JavaFX application.
From: Ladislav Török <ltorokrl@xxxxxxxxx>
To: concierge-dev@xxxxxxxxxxx
Date: 12/02/2014 02:02 PM
Subject: [concierge-dev] Concierge embedded in JavaFX application
Sent by: concierge-dev-bounces@xxxxxxxxxxx
I have a problem.
I am embedding (hosting) Concierge in JavaFX application.
I have created bundle. Bundle after install and start change background color in main javafx application, but after start bundle I get exception.
Is possible embedded-hosted Concierge in JavaFX application? Please any simple example. Thanks._______________________________________________
concierge-dev mailing list
concierge-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/concierge-dev
_______________________________________________
concierge-dev mailing list
concierge-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/concierge-dev
_______________________________________________
concierge-dev mailing list
concierge-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/concierge-dev
