Swing 应用程序和 osgi felix

发布于 2024-12-11 04:15:43 字数 952 浏览 1 评论 0原文

我创建了一个非常简单的捆绑包:

public class Main implements BundleActivator, ServiceListener{

public void start(BundleContext bc) throws Exception {

    bc.addServiceListener(this);

    //trivial system out
    System.out.println("started");

    //output to file
    FileWriter fw = new FileWriter("test.txt");
    fw.write("it has worked");
    fw.close();

    //opening of a frame
    JFrame f = new JFrame();
    JLabel l = new JLabel("test");
    f.add(l);
    f.setVisible(true);
    f.pack();

}

(other methods with empty body)

我编辑了清单文件:

Bundle-Name: Service listener example
Bundle-Description: A bundle that displays messages at startup and whe service events occur
Bundle-Vendor: Apache Felix
Bundle-Version: 1.0.0
Bundle-Activator: tosgi01.Main
Import-Package: org.osgi.framework

我将所有这些东西打包起来,启动了 felix 并: start file:testosgi.jar

它不会给出错误,但也不起作用。 有没有办法获得有关正在发生的事情的详细信息?

I've created a very simple bundle:

public class Main implements BundleActivator, ServiceListener{

public void start(BundleContext bc) throws Exception {

    bc.addServiceListener(this);

    //trivial system out
    System.out.println("started");

    //output to file
    FileWriter fw = new FileWriter("test.txt");
    fw.write("it has worked");
    fw.close();

    //opening of a frame
    JFrame f = new JFrame();
    JLabel l = new JLabel("test");
    f.add(l);
    f.setVisible(true);
    f.pack();

}

(other methods with empty body)

I've edited the manifest file:

Bundle-Name: Service listener example
Bundle-Description: A bundle that displays messages at startup and whe service events occur
Bundle-Vendor: Apache Felix
Bundle-Version: 1.0.0
Bundle-Activator: tosgi01.Main
Import-Package: org.osgi.framework

I've jar'ed up all this stuff, launched felix and:
start file:testosgi.jar

It doesn't gives an error, but doesn't work too.
Is there a way to get some detailed information on what's going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心房敞 2024-12-18 04:15:43

我不是 100% 确定,但我认为您必须在清单中指定 Bundle-SymbolicName。
您还必须导入 javax.swing 包(等等)。这些包默认不可用。

我们的应用程序的控制台中有很多输出,因此不能忽略一条消息。对我来说,停止和启动有问题的包通常会有所帮助。

您还应该尝试一下控制台/shell,它提供了诊断捆绑包问题的工具。

I'm not 100% sure but I think you must specify the Bundle-SymbolicName in your manifest.
You also have to import the javax.swing package (etc..). Those packages are by default not available.

We have a lot of output in the console in our application so it is o overlook a message. For me it often helps to stop and start he bundle in question.

You should also give the console/shell a try it offers tools to diagnose problems with bundles.

你怎么敢 2024-12-18 04:15:43

我无法直接帮助您,但以防万一您错过了:NetBeans 平台(基于 Swing 的 RCP)附带了 OSGi 和 Apache Felix 支持:

http://wiki.netbeans.org/OSGiAndNetBeans

I cannot directly help you, but in case you missed it: the NetBeans Platform (Swing based RCP) comes with OSGi and Apache Felix support:

http://wiki.netbeans.org/OSGiAndNetBeans

谎言月老 2024-12-18 04:15:43

在针对此类问题的众多调试选项中,Felix Web Console [1] 是我最喜欢的。

检查您的捆绑包是否处于活动状态,如果没有,请查看控制台捆绑包详细信息页面上的错误消息。如果您对 Swing 内容有疑问,您也可以首先将其删除,然后首先检查您的捆绑激活器是否确实被调用。

[1] http://felix.apache.org/site/apache- felix-web-console.html

Out of the many debugging options for such problems, the Felix Web Console [1] is my favorite.

Check that your bundle is active, and if not look at the error messages on the console's bundle details page. If you have doubts about the Swing stuff you can also remove it at first, and start by checking that your bundle activator is indeed called.

[1] http://felix.apache.org/site/apache-felix-web-console.html

顾铮苏瑾 2024-12-18 04:15:43

首先,您在清单中错过了“Bundle-SymbolicName”标签,这是强制性的。

其次,Felix 有一个名为 Gogo 的控制台包,它可以帮助您了解您的捆绑包是否已启动。只需安装此捆绑包并写入控制台

lb

,您就会看到已安装捆绑包的列表。找到您的捆绑包,如果它处于“活动”状态,则一切正常。如果没有,请写入

start

并查看日志。

如果没有帮助,请在文件conf/config.properties中找到felix.log.level=1行并将其更改为felix.log.level=4。您将在日志中看到启动捆绑包的整个过程。

First of all, you have missed "Bundle-SymbolicName" tag in your manifest, which is mandatory.

Second, Felix has a console bundle called Gogo, which can help you to understand is your bundle started or not. Just install this bundle and write into console

lb

and you will the the list of installed bundles. Find your bundle and if it has "active" state, everything is fine. If not, write

start <your_bundle_number>

and see the log.

If it doesn't help, find in file conf/config.properties line felix.log.level=1 and change it to felix.log.level=4. You will see in log whole process of starting bundle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文