【问题标题】:Unable to start OSGI framework on eclipse or after converting to jar无法在 Eclipse 上或转换为 jar 后启动 OSGI 框架
【发布时间】:2015-09-26 00:53:37
【问题描述】:

我正在开发一个 OSGI equinox 启动器,它应该启动 OSGI 框架和 equinox 控制台。我已将五个 jar 添加到一个名为插件的文件夹中,作为类路径/构建路径的一部分,但仍然无法执行。

以下是在 linux 控制台上成功执行并在 linux 控制台上打开 osgi> 提示符的命令。

java-Dosgi.bundles=org.eclipse.equinox.console_1.1.0.v20140131-1639.jar.@start,org.apache.felix.gogo.command_0.10.0.v201209301215.jar@start,org.apache。 felix.gogo.runtime_0.10.0.v201209301036.jar@start,org.apache.felix.gogo.shell_0.10.0.v201212101605.jar@start -jar org.eclipse.osgi_3.10.0.v20140606-1445.jar -console

但上面的代码在我的代码中失败了,如下所示

public static void main(String[] args) {

字符串命令="java-Dosgi.bundles=plugin/org.eclipse.equinox.console_1.1.0.v20140131-1639.jar@start,plugin/org.apache.felix.gogo.command_0.10.0.v201209301215.jar @start,plugin/org.apache.felix.gogo.runtime_0.10.0.v201209301036.jar@start,plugin/org.apache.felix.gogo.shell_0.10.0.v201212101605.jar@start -jar plugin/org.eclipse。 osgi_3.10.1.v20140909-1633.jar -console";

        try {


            // using the Runtime exec method:
            Process p = Runtime.getRuntime().exec(command);

            BufferedReader stdInput = new BufferedReader(new
                 InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new
                 InputStreamReader(p.getErrorStream()));

            // read the output from the command
            System.out.println("Here is the standard output of the command:\n");
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }

            // read any errors from the attempted command
            System.out.println("Here is the standard error of the command (if any):\n");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }

            System.exit(0);
        }
        catch (IOException e) {
            System.out.println("exception happened - here's what I know: ");
            e.printStackTrace();
            System.exit(-1);
        }
    }

错误如下 这是命令的标准输出:

这是命令的标准错误(如果有的话):

错误:无法访问jarfile插件/org.eclipse.osgi_3.10.1.v20140909-1633.jar

【问题讨论】:

    标签: java jakarta-ee osgi osgi-bundle dosgi


    【解决方案1】:

    这两个命令(在 Linux 控制台上成功执行的命令和在您的代码中失败的命令)略有不同。在您使用的第一个中

    -jar org.eclipse.osgi_3.10.0.v20140606-1445.jar
    

    第二个

    -jar plugin/org.eclipse.osgi_3.10.1.v20140909-1633.jar
    

    由于您收到的错误消息说它无法访问plugin/org.eclipse.osgi_3.10.1.v20140909-1633.jar,因此我假设此 jar 文件不存在,这就是您的命令失败的原因。

    【讨论】:

    • 即使我换了 jar 也没有同样的问题!!!即使控制台和eclipse中的命令都是一样的
    • 我假设由于您现在更改了 jar,因此错误消息也相应更改,对吧?你能检查两个命令(控制台和eclipse)是否相同吗?或者,您可以尝试为 jar 传递绝对路径,以确保 Eclipse 正在正确的位置查找它。
    • 如果我给出绝对路径,当我在 Eclipse 上运行它时,当我将项目转换为 jar 并将它作为 java -jar X.jar 运行时,我会在没有 osgi 控制台的情况下得到以下输出 这里是命令的标准输出:
    • @chetan 我在你的评论中看不到任何输出。你的意思是你没有得到任何输出?在这种情况下您会收到错误消息吗?
    猜你喜欢
    • 2013-09-12
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多