Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Custom module throw NoClassDefFoundError when runtime
HiI'm facing with a problem. When I create a custom rest module and add dependency like this
compileOnly group: "com.liferay", name: "com.liferay.dynamic.data.lists.api", version: "2.0.0"
and call service
DDLRecordSetLocalServiceUtil.getRecordSet(recordSetId);
But when I call service, it thrown
"Caused by: java.lang.NoClassDefFoundError: com/liferay/dynamic/data/lists/service/DDLRecordSetLocalServiceUtil"
More stranger, when I import POI :
compileOnly group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
compileOnly group: 'org.apache.poi', name: 'poi', version: '3.17'
And call service to create Excel File, It thrown the same error above. But I still founded those Libs in {liferay.home}/{tomcat.home}/webapps/ROOT/WEB-INF/lib
I use liferay-ce-7.0-ga7Can anyone help me? Thank for helping
compileOnly group: "com.liferay", name: "com.liferay.dynamic.data.lists.api", version: "2.0.0"
and call service
DDLRecordSetLocalServiceUtil.getRecordSet(recordSetId);
But when I call service, it thrown
"Caused by: java.lang.NoClassDefFoundError: com/liferay/dynamic/data/lists/service/DDLRecordSetLocalServiceUtil"
More stranger, when I import POI :
compileOnly group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
compileOnly group: 'org.apache.poi', name: 'poi', version: '3.17'
And call service to create Excel File, It thrown the same error above. But I still founded those Libs in {liferay.home}/{tomcat.home}/webapps/ROOT/WEB-INF/lib
I use liferay-ce-7.0-ga7Can anyone help me? Thank for helping
mika mika:
DDL: Most likely, you picked the wrong version: At compile time, version 2.0.0 is available, but at runtime it might be 1.4.5 or anything (I'm making this up - you'd have to look up what's actually contained in 7.0.6 GA7.
HiI'm facing with a problem. When I create a custom rest module and add dependency like this
compileOnly group: "com.liferay", name: "com.liferay.dynamic.data.lists.api", version: "2.0.0"
and call service
DDLRecordSetLocalServiceUtil.getRecordSet(recordSetId);
But when I call service, it thrown
"Caused by: java.lang.NoClassDefFoundError: com/liferay/dynamic/data/lists/service/DDLRecordSetLocalServiceUtil"
More stranger, when I import POI :
compileOnly group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
compileOnly group: 'org.apache.poi', name: 'poi', version: '3.17'
And call service to create Excel File, It thrown the same error above. But I still founded those Libs in {liferay.home}/{tomcat.home}/webapps/ROOT/WEB-INF/lib
I use liferay-ce-7.0-ga7Can anyone help me? Thank for helping
Related: Don't use the *LocalServiceUtil in the OSGi context, rather inject a @Reference to the localService directly into your @Component.
Obligatory link: Consider going through OSGi Basics.
For POI, similar: At compile time, it's no problem to provide the libraries. However, in the OSGi world, it's not sufficient to just drop stuff into WEB-INF/lib - you'll rather have to make it available to the OSGi runtime.
At least for a while (probably still today) POI wasn't packaged as OSGi bundle, so you might end up needing compileInclude, fattening your own bundle by packaging POI alongside. There's also a chapter on this in the OSGi Basics course. In general: If you can get along without compileInclude, that's preferable, but sometimes it just does the job.
Hi Olaf Kock
Thank for replying. I detect version of com.liferay.dynamic.data.lists.api is 2.1.10
But I don't know reason why it's always replace in dependencies with version 3.0.4
First I use compileOnnly. it doesn't work
I also use @Preference for DDLRecordSetLocalService but it still throws error ClassNotFound
After that, I use compileInclude or -includeresource to include Jar com.liferay.dynamic.data.lists.api-2.1.10.jar into module. It still not work and throws error " [com.liferay.dynamic.data.lists.exporter.DDLExporterFactory(2810)] The addDDLExporter method has thrown an exception. java.lang.IllegalArgumentException: argument type mismatch"
do you have any suggest for that?
Thank for replying. I detect version of com.liferay.dynamic.data.lists.api is 2.1.10
But I don't know reason why it's always replace in dependencies with version 3.0.4
First I use compileOnnly. it doesn't work
I also use @Preference for DDLRecordSetLocalService but it still throws error ClassNotFound
After that, I use compileInclude or -includeresource to include Jar com.liferay.dynamic.data.lists.api-2.1.10.jar into module. It still not work and throws error " [com.liferay.dynamic.data.lists.exporter.DDLExporterFactory(2810)] The addDDLExporter method has thrown an exception. java.lang.IllegalArgumentException: argument type mismatch"
do you have any suggest for that?
mika mika:
Hi Olaf Kock
Thank for replying. I detect version of com.liferay.dynamic.data.lists.api is 2.1.10
But I don't know reason why it's always replace in dependencies with version 3.0.4
First I use compileOnnly. it doesn't work
I also use @Preference for DDLRecordSetLocalService but it still throws error ClassNotFound
After that, I use compileInclude or -includeresource to include Jar com.liferay.dynamic.data.lists.api-2.1.10.jar into module. It still not work and throws error " [com.liferay.dynamic.data.lists.exporter.DDLExporterFactory(2810)] The addDDLExporter method has thrown an exception. java.lang.IllegalArgumentException: argument type mismatch"
do you have any suggest for that?
compileInclude on Liferay's own jars is a recipe for disaster, and must be avoided at all cost. There's no way to make it work. Apparently (according to your comment) your version comes with API in version 2.1.10, and you're including 2.0.0 - so you're introducing a conflict. No wonder that there's an argument type mismatch.
With regards to "changing" dependency numbers, note that you're declaring the dependency on the bundle's version, but bnd later rewrites this to the package's version, and they have nothing (much) to do with each other.
Did you go through OSGi Basics, as suggested? No need to repeat here what's covered there.
Thank you,I clear gradle cache and re-update dependencies and it resolved this problem