2016-03-28 79 views
0

我一直在试图端口Paul Bakker's@保罗 - 贝克Making JavaFX better with OSGi : javafx-osgi-example到使用Apache Maven的菲利克斯捆绑插件(BND)一个maven OSGi的项目。到目前为止,它编译没有任何错误,但我不能得到它运行:Maven的OSGi的项目编译,但不会跑

Starting OSGi Framework 
Found declarative services implementation: file:/C:/Users/Rev/.m2/repository/org/apache/felix/org.apache.felix.scr/1.6.2/org.apache.felix.scr-1.6.2.jar 
INFO : org.apache.felix.scr (1): Version = 1.6.2 
Bundle: org.apache.felix.framework 
    Registered service: [org.osgi.service.resolver.Resolver] 
    Registered service: [org.osgi.service.packageadmin.PackageAdmin] 
    Registered service: [org.osgi.service.startlevel.StartLevel] 
Bundle: org.apache.felix.scr 
    Registered service: [org.apache.felix.scr.ScrService] 
    Registered service: [org.osgi.service.cm.ManagedService] 
    Registered service: [org.apache.felix.scr.impl.ScrGogoCommand] 
DEBUG: Starting ComponentActorThread 
Bundle: null 
Bundle: null 
Bundle: null 

正如你所看到的,捆绑从未开始。没有错误被抛出。它只是根本不启动。

为什么捆绑不会启动?

项目源

  1. Paul Bakker's (The original non-maven project) : javafx-osgi-example

  2. My maven implementation of Paul Bakker's javafx-osgi-example : JavaFX-Maven-Multi-Module-OSGi

从终端(Windows),mvn clean install完美工作。

UPDATE

我一直在试图从Eclipse中运行它,但没有成功:

运行 - >运行为 - > Java应用程序


适用于Web开发人员的Eclipse Java EE IDE。

版本:Mars.2版本(4.5.2)
版本ID:20160218-0600


UPDATE

我有一个类在AppDIST打包rev.dist启动。它会循环通过rev下的所有目录,并启动名称与resources/plugins.txt下的名称相匹配的任何罐子。

APP.java

package rev.dist; 

import java.io.BufferedReader; 
import java.io.File; 
import java.io.IOException; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
import java.util.ServiceLoader; 
import java.util.stream.Collectors; 

import org.apache.commons.io.FilenameUtils; 
import org.osgi.framework.Bundle; 
import org.osgi.framework.BundleException; 
import org.osgi.framework.Constants; 
import org.osgi.framework.ServiceReference; 
import org.osgi.framework.launch.Framework; 
import org.osgi.framework.launch.FrameworkFactory; 

public class App { 

    FrameworkFactory frameworkFactory; 
    private Framework framework; 

    private List<String> pluginsList = new ArrayList<>(); 

    private int addedPlugins; 

    public static void main(String[] args) throws BundleException, URISyntaxException { 
     App app = new App(); 
     app.initialize(); 
    } 

    private void initialize() throws BundleException, URISyntaxException { 
     this.plugins(); 

     Map<String, String> map = new HashMap<String, String>(); 

     // make sure the cache is cleaned 
     map.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); 

     map.put("ds.showtrace", "true"); 
     map.put("ds.showerrors", "true"); 

     frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next(); 
     framework = frameworkFactory.newFramework(map); 

     System.out.println("Starting OSGi Framework"); 
     framework.init(); 

     loadScrBundle(framework); 

     File baseDir = new File("../"); 
     String baseDirPath = baseDir.getAbsolutePath(); 

     File[] files = new File(baseDirPath).listFiles(); 

     this.showFiles(files); 

     for (Bundle bundle : framework.getBundleContext().getBundles()) { 
      bundle.start(); 
      System.out.println("Bundle: " + bundle.getSymbolicName()); 
      if (bundle.getRegisteredServices() != null) { 
       for (ServiceReference<?> serviceReference : bundle.getRegisteredServices()) 
        System.out.println("\tRegistered service: " + serviceReference); 
      } 
     } 
    } 

    public void showFiles(File[] files) throws BundleException { 

     if (addedPlugins != pluginsList.size()) { 
      System.out.println(":: " + pluginsList.size()); 
      addedPlugins--; 
     } 

     for (File file : files) { 
      if (file.isDirectory()) { 
       // System.out.println("Directory: " + file.getName()); 
       showFiles(file.listFiles()); // Calls same method again. 
      } else { 
       String[] bits = file.getName().split("."); 
       if (bits.length > 0 && bits[bits.length - 1].equalsIgnoreCase("jar")) { 
        // framework.getBundleContext().installBundle(file.toURI().toString()); 
       } 

       // String ext = FilenameUtils.getExtension(file.getAbsolutePath()); 

       String basename = FilenameUtils.getBaseName(file.getName()); 

       if (pluginsList.contains(basename)) { 
        framework.getBundleContext().installBundle(file.toURI().toString()); 
        System.out.println("File: " + file.getName()); 

        System.out.println("Base >>>>>>>>>>>>> : " + basename); 

        pluginsList.remove(basename); 
       } 
      } 
     } 
    } 

    public void plugins() { 
     File plugins = new File("src/main/resources/plugins.txt"); 
     String fileName = plugins.getAbsolutePath(); 

     try (BufferedReader br = Files.newBufferedReader(Paths.get(fileName))) { 

      // br returns as stream and convert it into a List 
      pluginsList = br.lines().collect(Collectors.toList()); 

     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     pluginsList.forEach(System.out::println); 
     addedPlugins = pluginsList.size(); 
    } 

    private void loadScrBundle(Framework framework) throws URISyntaxException, BundleException { 
     URL url = getClass().getClassLoader().getResource("org/apache/felix/scr/ScrService.class"); 
     if (url == null) 
      throw new RuntimeException("Could not find the class org.apache.felix.scr.ScrService"); 
     String jarPath = url.toURI().getSchemeSpecificPart().replaceAll("!.*", ""); 
     System.out.println("Found declarative services implementation: " + jarPath); 
     framework.getBundleContext().installBundle(jarPath).start(); 
    } 
} 
+0

mvn clean install无法正常工作。 ui pom声明了对rev.launcher的依赖:launcher:1.0-SNAPSHOT和主屏幕pom声明了对rev.ui:ui:1.0-SNAPSHOT的依赖关系。目前正在构建的启动器和UI模块的组ID仅仅是“rev”。我想你在运行mvn install后重新命名组Ids,并从本地存储库中选取旧版本。 –

+1

dist中使用的程序集描述符使用moduleSet,但其他模块是rev:rev顶级pom的子程序。我认为你需要使用dependencySet请参阅http://stackoverflow.com/questions/17310482/the-maven-assembly-plugin-moduleset-sources-instructions-are-not-including-any-f。你能否更新有关如何构建和运行代码的更多细节? –

+0

你最近怎么发布它?这里几乎没有任何信息... –

回答

1

我已经发布了几个Drombler FX第一早期Access版本的 - JavaFX的模块化应用程序框架。

它不是基于Paul Bakker的工作,而是基于OSGi和Maven(POM-first)。也许你觉得它很有用。应用程序框架是开源的。

还有一个tutorialGetting Started页面。

相关问题