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

时间:2016-02-26 14:33:43

标签: tomcat osgi equinox eclipse-pde

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

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();
  ....

捆绑MANIFEST看起来像:

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

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

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

...,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

知道为什么会出现这样的错误吗?

如果从基础Web应用程序引用额外的系统包,如何编译Eclipse插件项目?

1 个答案:

答案 0 :(得分:1)

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

Eclipse使用自己的编译器ECJ,而不是JDK中的javac,它在遇到错误时表现不同。虽然javac将立即停止并且不产生任何输出,但ECJ确实生成类文件作为输出。但是,如果您尝试运行这些类,您将收到所看到的消息:

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

关于&#34;导入的消息无法解决&#34;来自Java编译器。如果你查看IDE中的源代码,你应该看到那里的红色X标记。

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