gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:52:39 25 4
gpt4 key购买 nike

我正在开发一个 Web 应用程序,在其中我在 servlet 上下文监听器(Eclipse Equinox 版本 3.10.0)中启动 osgi 框架。该 Web 应用程序在 Tomcat 8 和 Java 7 中运行。我已经开发并安装了 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();
....

bundle MANIFEST 看起来像这样:

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

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

在列出框架 header 时,我注意到在 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

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

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

最佳答案

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

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

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

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

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

关于tomcat - 如何编译从底层 webapp 引用额外系统包的 Eclipse 插件项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35654413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com