3

次のコードは、JDK7 を使用して Eclipse で問題なくコンパイルされます (私は更新 10 を使用していますが、JDK7 のどのバージョンでも再現できるはずです) が、まったく同じ JDK を使用してコマンド ラインからコンパイルすると失敗します。このクラスは、インターフェイス メソッドのスタブ実装を提供するだけです。

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.cert.X509Certificate;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;


public class TestBundle implements Bundle {

    /**
     * @param args
     */
    public static void main(String[] args) {


    }

    @Override
    public int compareTo(Bundle o) {

        return 0;
    }

    @Override
    public <A> A adapt(Class<A> arg0) {

        return null;
    }

    @Override
    public Enumeration<URL> findEntries(String arg0, String arg1, boolean arg2) {

        return null;
    }

    @Override
    public BundleContext getBundleContext() {

        return null;
    }

    @Override
    public long getBundleId() {

        return 0;
    }

    @Override
    public File getDataFile(String arg0) {

        return null;
    }

    @Override
    public URL getEntry(String arg0) {

        return null;
    }

    @Override
    public Enumeration<String> getEntryPaths(String arg0) {

        return null;
    }

    @Override
    public Dictionary<String, String> getHeaders() {

        return null;
    }

    @Override
    public Dictionary<String, String> getHeaders(String arg0) {

        return null;
    }

    @Override
    public long getLastModified() {

        return 0;
    }

    @Override
    public String getLocation() {

        return null;
    }

    @Override
    public ServiceReference<?>[] getRegisteredServices() {

        return null;
    }

    @Override
    public URL getResource(String arg0) {

        return null;
    }

    @Override
    public Enumeration<URL> getResources(String arg0) throws IOException {

        return null;
    }

    @Override
    public ServiceReference<?>[] getServicesInUse() {

        return null;
    }

    @Override
    public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(
            int arg0) {

        return null;
    }

    @Override
    public int getState() {

        return 0;
    }

    @Override
    public String getSymbolicName() {

        return null;
    }

    @Override
    public Version getVersion() {

        return null;
    }

    @Override
    public boolean hasPermission(Object arg0) {

        return false;
    }

    @Override
    public Class<?> loadClass(String arg0) throws ClassNotFoundException {

        return null;
    }

    @Override
    public void start() throws BundleException {


    }

    @Override
    public void start(int arg0) throws BundleException {


    }

    @Override
    public void stop() throws BundleException {


    }

    @Override
    public void stop(int arg0) throws BundleException {


    }

    @Override
    public void uninstall() throws BundleException {


    }

    @Override
    public void update() throws BundleException {


    }

    @Override
    public void update(InputStream arg0) throws BundleException {


    }

}

osgi の jar ファイルは、ここからダウンロードできます。

次のコマンドを使用して、コマンド ライン経由でこれをコンパイルしています。

javac.exe -cp org.eclipse.osgi_3.8.0.v20120529-1548.jar TestBundle.java

コマンドラインからコンパイルすると、次のエラーが発生します。

TestBundle.java:101: error: type ServiceReference does not take parameters
        public ServiceReference<?>[] getRegisteredServices() {
                               ^
TestBundle.java:119: error: type ServiceReference does not take parameters
        public ServiceReference<?>[] getServicesInUse() {
                               ^
TestBundle.java:18: error: TestBundle is not abstract and does not override abstract method adapt(Class) in Bundle
public class TestBundle implements Bundle {
       ^
TestBundle.java:28: error: method does not override or implement a method from a supertype
        @Override
        ^
TestBundle.java:35: error: name clash: <A>adapt(Class<A>) in TestBundle and adapt(Class) in Bundle have the same erasure, yet neither overrides the other
        public <A> A adapt(Class<A> arg0) {
                     ^
  where A is a type-variable:
    A extends Object declared in method <A>adapt(Class<A>)
TestBundle.java:34: error: method does not override or implement a method from a supertype
        @Override
        ^
6 errors
4

3 に答える 3

12

OSGi 仕様のバンドルは、Java 7 でコンパイルするとジェネリックに問題があります。これは、バンドルが jdk 1.4 の下位互換性を備えてコンパイルされたため、Jdk 7 で機能しなくなるためです。多くの苦情の後、に準拠した新しいバージョンがリリースされました。 jdk7になりました。

4.3.1 のソースは 4.3.0 と同じです。再コンパイルされるだけです。この jar を使用してコードをコンパイルできるはずです。これがあなたが使用した Eclipse の jar とどのように関連しているかはわかりませんが、コンパイルされた古い仕様クラスを使用しただけだと思います。

http://search.maven.org/remotecontent?filepath=org/osgi/org.osgi.core/4.3.1/org.osgi.core-4.3.1.jar

于 2012-12-18T08:24:41.243 に答える
0

間違ったjarファイル名について言及しました-「org.eclipse.osgi_3.8.0.v20120529-1548.jar」正しいファイル名はorg.eclipse.osgi-3.8.0.v20120529-1548.jarです

このコマンド: javac.exe -cp org.eclipse.osgi-3.8.0.v20120529-1548.jar TestBundle.java

私のために働いています

于 2012-12-18T06:19:00.250 に答える
0

コマンドラインからjavac *を使用してコードをコンパイルすることができました.jarから他の(Eclipse関連と思われる)エントリをいくつか削除し、クラスとパッケージのみを保持しました。jar のクリーン バージョンはこちらです。

また、通常は Eclipse によって導入される @Override アノテーションも削除しました。

于 2012-12-18T06:03:03.830 に答える