OSGI Portlet Struts java.lang.NoClassDefFoundError

76 views
Skip to first unread message

NightDream

unread,
May 20, 2021, 11:07:37 PM5/20/21
to dotCMS User Group

Hi,

I'm keep getting java.lang.NoClassDefFoundError when I use the OSGI plugin-seed struts portlet from github.
Any idea how to solve this?

Steps to reproduce:
1) Run dotCMS 5.2.1
2) Download the portlet example (v5.2.1) from plugin-seed github
3) Change the code as below:
Capture1.JPG

4) Upload on dotCMS plugin
5) Add Export Packages:
com.dotcms.repackage.javax.portlet,
com.dotcms.repackage.org.apache.struts.action,
com.dotcms.repackage.org.apache.struts.config,
org.apache.logging.log4j,
org.apache.logging.log4j.core,
org.apache.logging.log4j.spi,
6) Start the plugin
7) Add Portlets on the tabs for CMS Administrator
8) Error shown as below:
Capture3.JPG

Logs:
Capture.JPG

Falzone, Chris

unread,
May 21, 2021, 2:40:20 PM5/21/21
to dot...@googlegroups.com
Anything relevant in the logs when you deploy the plugin?  If not, you might have to try and create an instance of the class in your plugin activator to see the "actual" error.  My guess is something is not getting imported that needs to be.  

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/40080c33-c03f-4041-9a4e-8df948dc0856n%40googlegroups.com.


--

Christopher Falzone

DevOps Engineer

A Q U E N T  /  VITAMIN T

NightDream

unread,
May 21, 2021, 2:57:35 PM5/21/21
to dotCMS User Group
Hi Chris,

I have attached the full logs on the attachment.
For this log, I'm running on clean dotcms 5.2.8.4 with seed plugin 5.2.8 on github.
There is no error when I deployed the plugin.
dotcms.log

NightDream

unread,
May 21, 2021, 3:11:29 PM5/21/21
to dotCMS User Group
If I didn't add the class and upload the original example portlet plugin, it is working.
Once I add the new class, compile (gradlew.bat jar), then upload (builds/libs/com.dotcms.portlet-0.2.jar) on dotCMS plugin.
Then it shows "....NoClassDefFoundError....".
Below is my build.gradle:

Capture.JPG

Falzone, Chris

unread,
May 21, 2021, 3:12:26 PM5/21/21
to dot...@googlegroups.com
When you built the plugin, did it create a fragment plugin and was this also deployed?  That might be what is missing here, I am not familiar with this particular plugin seed, but that is the common practice with their examples.

Otherwise, like I said, you'll have to find a way to create an instance of the class in your activator so you can see the full stack trace on why the class cannot be instantiated.  At least that is the best way I have found to sus it out.  OSGI can be a pain to work with when things don't work as you want.  

Another thing might be that something changed in the plugin seed that made it no longer compatible with the older version.  

NightDream

unread,
May 21, 2021, 3:27:33 PM5/21/21
to dotCMS User Group
Yes when i build, it drop me two jar. One is the plugin, another is a fragment.
I just deployed the fragment plugin as well, seems not working as well.
Will try to create instance of the class in my activator and check on the log.

Capture.JPG

NightDream

unread,
May 21, 2021, 3:50:03 PM5/21/21
to dotCMS User Group
I have create an instance of class on Activator, it seems working well
It is something like this?

Capture.JPG

Capture1.JPG

jonathan...@dotcms.com

unread,
May 21, 2021, 3:59:30 PM5/21/21
to dotCMS User Group
Hi NightDream

What do you want to achieve? there may be other ways to meet your requirements

Best,
J

NightDream

unread,
May 21, 2021, 4:18:36 PM5/21/21
to dotCMS User Group
Hi Jonathan,

I'm working with dotCMS upgrade from 3.7 to 5.2
My dotCMS 3.7 seems work well with the portlets and able to instantiated and access to other class
What I want to achieve is how to access other Class in this Action Class for dotCMS 5.2?

Capture1.JPG

jonathan...@dotcms.com

unread,
May 22, 2021, 3:11:35 PM5/22/21
to dotCMS User Group
I see, could you please share the build.gradle

I would like to try to reproduce it locally

thanks,
J

NightDream

unread,
May 22, 2021, 9:06:38 PM5/22/21
to dotCMS User Group
Hi Jonathan,

Attached is the build.gradle for dotCMS 5.2.8.4.
It should exactly same as below:

build.gradle.txt

jonathan...@dotcms.com

unread,
May 25, 2021, 4:46:10 PM5/25/21
to dotCMS User Group
Hi NightDream

Thanks for sharing the information, I am able to reproduce it locally and tracking the progress on the research here: https://github.com/dotcms/core/issues/20445

Best,
J

Falzone, Chris

unread,
May 25, 2021, 4:52:21 PM5/25/21
to dot...@googlegroups.com
I wonder if the issue is similar to quartz jobs accessing classes created in the same OSGI plugin.  Because struts in dotCMS is using the main classloader not the osgi classloader, you have to expose the testing class to the main classloader by exporting it maybe?

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.

jonathan...@dotcms.com

unread,
May 25, 2021, 5:56:59 PM5/25/21
to dotCMS User Group
Hi Chris, it will depending how is in charge of instance the class.
If the class is created by reflection on dotCMS probably need to inject on the dotCMS classloader, otherwise would be ok

jonathan...@dotcms.com

unread,
May 25, 2021, 6:00:26 PM5/25/21
to dotCMS User Group
Hi NightDream

Here you can see how we have done to avoid the classloader issue:


Basically you need to inject the class Testing into the dotCMS classloader (powered by bytebuddy java agent)

```
public class Activator extends GenericBundleActivator {

private LoggerContext pluginLoggerContext;

@SuppressWarnings ("unchecked")
public void start ( BundleContext context ) throws Exception {

//Initializing log4j...
LoggerContext dotcmsLoggerContext = Log4jUtil.getLoggerContext();
//Initialing the log4j context of this plugin based on the dotCMS logger context
pluginLoggerContext = (LoggerContext) LogManager
.getContext(this.getClass().getClassLoader(),
false,
dotcmsLoggerContext,
dotcmsLoggerContext.getConfigLocation());

//Initializing services...
initializeServices ( context );
this.overrideClass(Testing.class);

```

Haven't try but on 5.x it would be worthy to try:

this.addClassTodotCMSClassLoader(Testing.class.getName()); // 5.x series

Let me know if you get it fixed, 

Best
J

On Saturday, May 22, 2021 at 7:06:38 PM UTC-6 NightDream wrote:

NightDream

unread,
May 28, 2021, 11:02:10 PM5/28/21
to dotCMS User Group
Hi Jonathan,

Thanks for the help, it is working with addClassTodotCMSClassLoader

jonathan...@dotcms.com

unread,
Jun 1, 2021, 5:05:54 PM6/1/21
to dotCMS User Group
Awesome, I am glad you get it working

Best,
J
Reply all
Reply to author
Forward
0 new messages