我写了一个只包含这个类的Liferay 7模块:
...
@Component(
immediate = true,
property = {
"servlet-context-name=",
"servlet-filter-name=myfilter",
"url-pattern=/*"
},
service = Filter.class
)
public class MyFilter extends BaseFilter {
...
}
它编译得很好,但是在新安装的Liferay 7上部署它会出现此错误:
STARTED com.liferay.marketplace.deployer_2.0.9 [170]
STARTED mymodule_1.0.0 [668]
[mymodule:97] BundleComponentActivator : Bundle [668] Unexpected failure enabling component holder my.MyFilter
java.lang.NoClassDefFoundError: com/liferay/portal/kernel/servlet/BaseFilter
at java.lang.ClassLoader.defineClass1(Native Method)
[...]
Caused by: java.lang.ClassNotFoundException: com.liferay.portal.kernel.servlet.BaseFilter cannot be found by mymodule_1.0.0
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:444)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:357)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:349)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 48 more
我做错了什么?
这是我的模块build.gradle
:
dependencies {
compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.spring.extender", version: "2.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.security.audit.api", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.configuration.metatype", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.document.library.web", version: "1.0.10"
compileOnly group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
compileOnly group: "javax.servlet", name: "servlet-api", version: "2.5"
compileOnly group: "org.osgi", name:"org.osgi.service.component.annotations", version:"1.3.0"
}
答案 0 :(得分:0)
此错误表示您的捆绑包应导入包com.liferay.portal.kernel.servlet
。
OSGi包只能从它们直接包含或使用Import-Package
清单标头明确导入的包中加载。
答案 1 :(得分:0)
我认为你的jar Manifest缺少com.liferay.portal.kernel.servlet
的包导入。
如何创建捆绑包?
导致此问题的典型错误是手动配置导入的包并错过,*
以启用该bnd自动分析导入。