在Tomcat上为Liferay部署OSGi模块时,“未解决的要求:导入包:javax.ws.rs”

时间:2019-06-14 10:33:22

标签: java maven tomcat liferay osgi

我目前正在Maven项目中使用JAX-RS和Jackson开发REST API,但是当我尝试将其部署到服务器时遇到了一些问题。

2019-06-14 11:35:18.832 INFO  [Refresh Thread: Equinox Container: 9d0f0e6b-9ad0-4d64-b221-2bde32f797ee][BundleStartStopLogger:39] STARTED XXXXREST_1.0.0 [1004]
2019-06-14 11:35:19.801 ERROR [fileinstall-C:/liferay-ce-portal-7.1.2-ga3/osgi/modules][org_apache_felix_fileinstall:97] Error while starting bundle: file:/C:/liferay-ce-portal-7.1.2-ga3/osgi/modules/XXXXREST.jar 
org.osgi.framework.BundleException: Could not resolve module: com.xxxx.xxxx [995]_  Unresolved requirement: Import-Package: javax.ws.rs; version="[1.1.0,2.0.0)"_ [Sanitized]
    at org.eclipse.osgi.container.Module.start(Module.java:444)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1258)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1230)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1218)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:507)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312)
2019-06-14 11:35:19.816 ERROR [fileinstall-C:/liferay-ce-portal-7.1.2-ga3/osgi/modules][org_apache_felix_fileinstall:97] Error while starting bundle: file:/C:/liferay-ce-portal-7.1.2-ga3/osgi/modules/XXXXREST.jar 
org.osgi.framework.BundleException: Could not resolve module: com.xxxxx.xxxxx [995]_  Unresolved requirement: Import-Package: javax.ws.rs; version="[1.1.0,2.0.0)"_ [Sanitized]
    at org.eclipse.osgi.container.Module.start(Module.java:444)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1258)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1230)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:512)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312)
2019-06-14 11:35:33.958 INFO  [Refresh Thread: Equinox Container: 9d0f0e6b-9ad0-4d64-b221-2bde32f797ee][PortletHotDeployListener:288] 1 portlet for XXXXREST is available for use
2019-06-14 11:35:35.599 ERROR [Refresh Thread: Equinox Container: 9d0f0e6b-9ad0-4d64-b221-2bde32f797ee][com_liferay_portal_osgi_web_wab_extender:97] Catastrophic initialization failure! Shutting down XXXXREST WAB due to: The URI scheme bundleentry of the URI bundleentry://995.fwk1108589630/com/xxxxx/xxxxxx/domain/CommunityResource.class is not supported. Package scanning deployment is not supported for such URIs._Try using a different deployment mechanism such as explicitly declaring root resource and provider classes using an extension of javax.ws.rs.core.Application  [Sanitized]
com.sun.jersey.core.spi.scanning.ScannerException: The URI scheme bundleentry of the URI bundleentry://995.fwk1108589630/com/xxxxx/xxxxx/domain/CommunityResource.class is not supported. Package scanning deployment is not supported for such URIs._Try using a different deployment mechanism such as explicitly declaring root resource and provider classes using an extension of javax.ws.rs.core.Application [Sanitized]
    at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:228)
    at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:142)
    at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80)
    at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
    at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
    at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
    at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
    at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:205)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at com.liferay.portal.osgi.web.wab.extender.internal.adapter.AsyncAttributeAdapterServlet.init(AsyncAttributeAdapterServlet.java:54)
    at com.liferay.portal.osgi.web.wab.extender.internal.adapter.ServletExceptionAdapter.init(ServletExceptionAdapter.java:62)
    at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.init(EndpointRegistration.java:95)
    at org.eclipse.equinox.http.servlet.internal.context.ContextController.doAddServletRegistration(ContextController.java:566)
    at org.eclipse.equinox.http.servlet.internal.context.ContextController.addServletRegistration(ContextController.java:440)
    at org.eclipse.equinox.http.servlet.internal.customizer.ContextServletTrackerCustomizer.addingService(ContextServletTrackerCustomizer.java:55)
    at org.eclipse.equinox.http.servlet.internal.customizer.ContextServletTrackerCustomizer.addingService(ContextServletTrackerCustomizer.java:1)
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:943)
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
    at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:903)
    at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:891)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:804)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:228)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:487)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:1004)
    at com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor.initServlets(WabBundleProcessor.java:692)
    at com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor.init(WabBundleProcessor.java:225)
    at com.liferay.portal.osgi.web.wab.extender.internal.WebBundleDeployer._initWabBundle(WebBundleDeployer.java:186)
    at com.liferay.portal.osgi.web.wab.extender.internal.WebBundleDeployer.doStart(WebBundleDeployer.java:85)
    at com.liferay.portal.osgi.web.wab.extender.internal.WabFactory$WABExtension.start(WabFactory.java:175)
    at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
    at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:488)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:1)
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)
    at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:450)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:230)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:137)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:129)
    at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:191)
    at org.eclipse.osgi.container.Module.publishEvent(Module.java:476)
    at org.eclipse.osgi.container.Module.start(Module.java:467)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:468)
    at org.eclipse.osgi.container.ModuleContainer.start(ModuleContainer.java:777)
    at org.eclipse.osgi.container.ModuleContainer.applyDelta(ModuleContainer.java:768)
    at org.eclipse.osgi.container.ModuleContainer.resolveAndApply(ModuleContainer.java:538)
    at org.eclipse.osgi.container.ModuleContainer.resolve(ModuleContainer.java:484)
    at org.eclipse.osgi.container.ModuleContainer.refresh(ModuleContainer.java:1028)
    at org.eclipse.osgi.container.ModuleContainer$ContainerWiring.dispatchEvent(ModuleContainer.java:1409)
    at org.eclipse.osgi.container.ModuleContainer$ContainerWiring.dispatchEvent(ModuleContainer.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

显然,它与javax.ws.rs包有关。也许Liferay或Tomcat使用的是自己的依赖项,而该依赖项会与我使用的版本冲突?

到目前为止,我已经尝试将此行添加到我的bnd.bnd文件中:

Import-Package: javax.ws.rs; version="[1.1.0,2.0.0)"

我还尝试在pom.xml上添加依赖项(我尝试了多个版本:2.0、2.0.1、2.1、2.1.1):

<dependency>
     <groupId>javax.ws.rs</groupId>
     <artifactId>javax.ws.rs-api</artifactId>
     <version>2.1.1</version>
</dependency>

我还尝试将那些 javax.ws.rs-api-2.X.X.jar

添加到项目的构建路径中

关于什么原因的任何想法?我不知道该怎么办。

谢谢。

1 个答案:

答案 0 :(得分:1)

与Miroslav的评论相反,我在提供的依赖项中找不到javax.ws.rs-api。因此,您可以通过依赖项声明来满足构建时的依赖关系(对于编译器)。

生成的工件(您自己的捆绑包)仍然对javax.ws.rs-api-*。jar具有运行时依赖关系,您还需要对其进行部署:只需将其放入${liferay.home}/deploy夹。现在,它可以用于任何即将依赖它的捆绑软件。

我怀疑米罗斯拉夫(Miroslav)前一段时间做过此事,现在在他的运行时中可以使用它。还是我测试了错误的版本(使用了DXP 7.2)或错过了某些内容。