0

我有一个实现 osgi 框架的 tomcat 服务器,其中预先部署了 osgi 包来证明 jsp 和 servlets webapps。使用的 Tomcat 版本是 6.0.24。这个 tomcat 安装捆绑了一个流行的行业工具。我不应该安装任何版本的 java 或设置 JAVA_HOME 以使 tomcat 工作。JAVA libs 和 bin 由工具本身提供,提供的版本为 1.6。

我有兴趣将自己的捆绑包添加到现有的 tomcat 中。因此,我在另一台具有 java 1.7 的机器上开发并测试了一个示例包,并且所选编译器的兼容性为 1.6,该包在其他机器上运行良好。当我部署捆绑包时,它具有已解决的状态,但是当我尝试启动捆绑包时,它会抛出“不支持的 major.minor 版本 51”。

更新:显然我部署了一个旧版本的包,它仍然在 java 1.7 中编译,我重新编译了具有 1.6 兼容性的包,并且包现在处于活动状态。

    osgi> ss sample

    Framework is launched.

    id      State       Bundle
    77      RESOLVED    sample.http2_1.0.0.2

    osgi> start 77
    org.osgi.framework.BundleException: The activator sample.http2.Activator for bundle sample.http2 is invalid
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:157)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:750)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
    at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:253)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:155)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:303)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:288)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:224)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.UnsupportedClassVersionError: sample/http2/Activator : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:183)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:576)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:546)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:477)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:465)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:445)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:211)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:376)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:452)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:405)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:393)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:321)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:231)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:150)
    ... 14 more
    Nested Exception:
    java.lang.UnsupportedClassVersionError: sample/http2/Activator : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:183)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:576)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:546)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:477)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:465)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:445)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:211)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:376)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:452)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:405)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:393)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:321)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:231)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:150)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:750)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
    at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:253)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:155)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:303)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:288)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:224)
    at java.lang.Thread.run(Thread.java:619)
    Nested Exception:
    java.lang.UnsupportedClassVersionError: sample/http2/Activator : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:183)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:576)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:546)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:477)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:465)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:445)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:211)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:376)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:452)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:405)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:393)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:321)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:231)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:150)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:750)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
    at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:253)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:155)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:303)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:288)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:224)
    at java.lang.Thread.run(Thread.java:619)

    osgi>       
4

1 回答 1

1

您的类文件是为 Java 7(版本=51)编译的,但您(可能)在 Java 6(版本=50)上运行它,请参阅wikipedia

所以这只是虚拟机在一个未知的类文件上犹豫不决。请注意,java 有不同的兼容性设置。有 Java 源级兼容性和 Java 目标级兼容性。类格式文件版本由目标兼容性设置,请参见另一个 stackoverflow 问题。在 javac 中,您要指定 -target 1.6。

当您在 OSGi 中使用 OSGi Bundle-RequiredExecutionEnvironment选项时,您可以在启动应用程序之前获得更易读的错误。

于 2013-04-11T14:47:50.210 回答