当前位置: 首页 > 知识库问答 >
问题:

如何编译引用底层webapp的额外系统包的Eclipse插件项目?

傅星光
2023-03-14

我正在开发一个webapp,我在servlet上下文监听器中启动osgi框架(Eclipse Equinox版本3.10.0)。Webapp在Tomcat 8和Java7中运行。我已经开发并安装了2个简单的包,只要它们使用它们的内部类就可以正常工作。但是当我尝试将webapp包导入到system.package.extra配置的bundles中时,bundles无法解析这些包:

java.lang.Error: Unresolved compilation problems: 
    The import xxx.xxxxxxxx cannot be resolved

框架这样声明额外的系统包:

public void contextInitialized(ServletContextEvent cntxt) {
Iterator<FrameworkFactory> frameworkFactoryIt = ServiceLoader.load(FrameworkFactory.class).iterator();
boolean frameworkStarted = false;
while (frameworkFactoryIt.hasNext() && !frameworkStarted) {
  FrameworkFactory frameworkFactory = frameworkFactoryIt.next();
  Map<String, String> config = new HashMap<String, String>();
  config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "xxx.xxxxxxxx,...");
  config.put(Constants.FRAMEWORK_STORAGE, "/users/peveuve/osgi-cache");
  config.put(Constants.FRAMEWORK_STORAGE_CLEAN, "true");
  framework = frameworkFactory.newFramework(config);
  framework.start();
  ....

捆绑包清单如下所示:

Import-Package: org.osgi.framework;version="1.3.0",
 xxx.xxxxxxxx;resolution:=optional,

导入的包是可选的,以避免Eclipse插件项目中的错误。我不使用版本控制。

当列出框架标题时,我注意到导出包中的系统包和我的额外系统包之间有一个空格字符:

...,org.xml.sax.helpers, xxx.xxxxxxxx,...

由于它是由框架本身添加的,我想这不是问题,但谁知道呢。

以下是完整的堆栈跟踪:

!SESSION 2016-02-26 16:07:35.175 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_79
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=fr_FR

!ENTRY com.amfinesoft.kheops.service.user 4 0 2016-02-26 16:07:35.176
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.ServiceException: Exception in com.amfinesoft.kheops.service.user.UserServiceFactory.getService()
    at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.factoryGetService(ServiceFactoryUse.java:222)
    at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.getService(ServiceFactoryUse.java:111)
    at org.eclipse.osgi.internal.serviceregistry.ServiceConsumer$2.getService(ServiceConsumer.java:45)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:496)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.getService(ServiceRegistry.java:461)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.getService(BundleContextImpl.java:619)
    at com.amfinesoft.kheops.consumer.user.UserConsumerActivator.start(UserConsumerActivator.java:24)
    at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771)
    at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:721)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:936)
    at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:319)
    at org.eclipse.osgi.container.Module.doStart(Module.java:571)
    at org.eclipse.osgi.container.Module.start(Module.java:439)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:454)
    at org.eclipse.osgi.container.ModuleContainer.applyDelta(ModuleContainer.java:717)
    at org.eclipse.osgi.container.ModuleContainer.resolveAndApply(ModuleContainer.java:491)
    at org.eclipse.osgi.container.ModuleContainer.resolve(ModuleContainer.java:437)
    at org.eclipse.osgi.container.ModuleContainer.resolve(ModuleContainer.java:427)
    at org.eclipse.osgi.container.Module.start(Module.java:416)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1562)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)
    at org.eclipse.osgi.container.SystemModule.startWorker(SystemModule.java:242)
    at org.eclipse.osgi.container.Module.doStart(Module.java:571)
    at org.eclipse.osgi.container.Module.start(Module.java:439)
    at org.eclipse.osgi.container.SystemModule.start(SystemModule.java:172)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:393)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:412)
    at org.eclipse.osgi.launch.Equinox.start(Equinox.java:115)
    at com.amfinesoft.kheops.service.starter.OSGIServletContextListener.contextInitialized(OSGIServletContextListener.java:60)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.Error: Unresolved compilation problems: 
    The import com.eclipsesource cannot be resolved
    The import com.eclipsesource cannot be resolved
    The import kheops cannot be resolved
    The import kheops cannot be resolved
    The import kheops cannot be resolved
    The import system cannot be resolved
    The type UserServiceImpl must implement the inherited abstract method UserServiceIntf.listOfUsers(KCommand, KBrowser)
    KCommand cannot be resolved to a type
    KCommand cannot be resolved to a type
    KBrowser cannot be resolved to a type
    JsonArray cannot be resolved to a type
    JsonArray cannot be resolved to a type
    The method getTrees() is undefined for the type DBUserFinder
    The method getTrees() is undefined for the type DBUserContainer
    JsonValue cannot be resolved
    Logger cannot be resolved
    KCommandProcessor cannot be resolved

    at com.amfinesoft.kheops.service.user.impl.UserServiceImpl.<init>(UserServiceImpl.java:7)
    at com.amfinesoft.kheops.service.user.UserServiceFactory.getService(UserServiceFactory.java:14)
    at com.amfinesoft.kheops.service.user.UserServiceFactory.getService(UserServiceFactory.java:1)
    at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse$1.run(ServiceFactoryUse.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.factoryGetService(ServiceFactoryUse.java:210)
    ... 41 more

你知道为什么会发生这样的错误吗?

当Eclipse插件项目引用来自底层Web应用程序的额外系统包时,如何编译它?

共有1个答案

穆飞星
2023-03-14

这根本不是OSGi错误。这是部署未正确编译的代码的结果。

Eclipse使用自己的名为ECJ的编译器,而不是来自JDK的javac,后者在遇到错误时的行为会有所不同。尽管javac将立即停止并不会生成任何输出,但ECJ会生成类文件作为输出。但是,如果您尝试运行这些类,您将看到以下消息:

java.lang.Error: Unresolved compilation problems: 
    The import xxx.xxxxxxxx cannot be resolved

关于“导入无法解析”的消息来自Java编译器。如果您查看IDE中的源代码,您应该会看到红色的X标记。

基本上,在尝试运行代码之前,您必须确保代码实际编译时没有错误。

 类似资料:
  • 在ApacheFelixOSGi框架中,配置文件提供了在Felix生态系统中包含其他系统包的选项。Felix配置中的行如下所示: 我将当前的OSGi框架从Felix切换到EclipseEquinox,我发现我的一个捆绑包依赖于包,但在Equinox的(模糊的)配置文档中找不到任何与Felix中的设置等效的东西。有人知道Equinox的方式包括这个额外的包吗? 如果您正在查看我在上面共享的链接(到E

  • 编译 Java 项目 一个项目可以关联多个编译器。 java 项目关联的是 java 编译器。可以通过以下方式来查看项目关联的编译器: 在 Package Explorer 视图中鼠标右击项目并选择 Properties 在左侧的树形菜单中点击 Builders java编译器用于编译java项目。通过点 New 按钮我们可以让java项目关联 Ant builder 编译器。 java 编译器通

  • 当我通过Eclipse运行Gradle项目时,我得到以下错误。

  • 我从一个全新的java库项目开始,该项目由任务生成。然后,我按照gradle java插件用户指南中给出的步骤添加了一个integrationTest任务:https://docs.gradle.org/current/userguide/java_testing.html#sec:configuring_java_integration_tests.但是现在gradle eclipse插件在中不

  • 本文向大家介绍Python调用系统底层API播放wav文件的方法,包括了Python调用系统底层API播放wav文件的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Python调用系统底层API播放wav文件的方法。分享给大家供大家参考,具体如下: 这里未使用其他库,只是使用 pywin32 调用系统底层 API 播放 wav 文件。 具体代码如下: 更多关于Python相关内容感兴