0

コードでバンドルをコンパイルする場合

    package ihtika2.mainform;

import com.google.code.ihtika.Vars.Ini;
import ihtika2.mainform.service.MainFormInterface;
import java.util.HashSet;
import java.util.Hashtable;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.wiring.FrameworkWiring;

public class Activator implements BundleActivator {

    @Override
    public void start(BundleContext context) throws Exception {
        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put("Funct", "MainForm");
        context.registerService(MainFormInterface.class.getName(), new MainForm(), props);

        ServiceReference[] refs = context.getServiceReferences(
                MainFormInterface.class.getName(), "(Funct=MainForm)");
        if (refs == null) {
            System.out.println("Not Found MainForm on start");
        } else {
            MainFormInterface MainForm = (MainFormInterface) context.getService(refs[0]);
            MainForm.sendContext(context);
            MainForm.showWindow();
        }

        int x = 0;
        for (Bundle qqq : context.getBundles()) {
            if (x < 1) {
                HashSet<Bundle> bundles;
                bundles = new HashSet<Bundle>();
                bundles.add(qqq);
                HashSet<Bundle> depends = (HashSet<Bundle>) context.getBundle(0).adapt(FrameworkWiring.class).getDependencyClosure(bundles);
                System.out.println("---");
                System.out.println(qqq.getSymbolicName());
                System.out.println("+++");
                for (Bundle depends1 : depends) {
                    System.out.println(depends1.getSymbolicName());
                }
            }
                x++;
        }

エラーが発生します

cd C:\Art\Dropbox\OpenSource\MyGIT\ihtika\Sources\Bundles\I_MainForm; JAVA_HOME=C:\\Java\\jdk1.7.0_06 "\"C:\\Program Files\\NetBeans Dev 201208160001\\java\\maven\\bin\\mvn.bat\"" clean install
Scanning for projects...

------------------------------------------------------------------------
Building I_MainForm OSGi Bundle 1.0-SNAPSHOT
------------------------------------------------------------------------

[clean:clean]
Deleting C:\Art\Dropbox\OpenSource\MyGIT\ihtika\Sources\Bundles\I_MainForm\target

[resources:resources]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
Copying 1 resource

[compiler:compile]
Compiling 5 source files to C:\Art\Dropbox\OpenSource\MyGIT\ihtika\Sources\Bundles\I_MainForm\target\classes
-------------------------------------------------------------
COMPILATION ERROR : 
-------------------------------------------------------------
ihtika2/mainform/Activator.java:[38,109] error: cannot find symbol
1 error
-------------------------------------------------------------
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.886s
Finished at: Tue Aug 21 12:21:25 MSK 2012
Final Memory: 10M/25M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project I_MainForm: Compilation failure
\Art\Dropbox\OpenSource\MyGIT\ihtika\Sources\Bundles\I_MainForm\src\main\java\ihtika2\mainform\Activator.java:[38,109] error: cannot find symbol
-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

このコードをコンパイルする方法を教えてください。私は apache-maven-2.2.1、jdk1.7.0_06 を使用し、1.6 コード用にコンパイルします (NetBeans プロジェクトで設定)。興味深いことに、NetBeans はこの文字列 (Activator.java:[38,109]) でエラーを表示せず、このコードは正しいと見なします。

4

2 に答える 2

1

osgi.core バージョン 4.3 以降を使用する必要があります。FrameworkWiring タイプは osgi.core 4.3 で導入されました。http://mvnrepository.com/artifact/org.osgi/org.osgi.core/4.3.0

Apache Felix 4.0 では、osgi.core 4.3 のサポートが追加されました。http://www.infoq.com/news/2011/09/felix-400

于 2012-08-21T12:58:55.790 に答える
0

問題は、Felix 4.0.3 および org.osgi.core (4.3.0) jar バンドルにあり、Central Maven リポジトリから入手できます。

時代遅れだと思います。

私が理解している限りでは、Osgi バージョン (4.3) にもリビジョンがあります。

おそらく中央 Maven リポジトリのライブラリが古くなっています。

解決策 - ソースをダウンロードしてコンパイルします

https://svn.apache.org/repos/asf/felix/trunk/フレームワーク。

つまり、ソースのダウンロード後、ソースのあるフォルダーに:

cd フレームワーク

mvn インストール

このコマンドは、Felix をコンパイルして、ローカルの Maven リポジトリにインストールします。この後、Central Maven リポジトリのバンドルの代わりに、新しい Felix のバンドル (SNAPSHOT) を使用できます。

私の悪い英語を申し訳ありません。

于 2012-08-21T17:45:10.477 に答える