Extension object creation fails due to different class loaders within Eclipse

120 views
Skip to first unread message

marge...@gmail.com

unread,
Jun 14, 2020, 12:56:48 AM6/14/20
to pf4j
HI, Appreciate any help here.

I am using pf4j within spring boot and am able to load plugins/extensions and invoke them when running the app from command line. From within eclipse though it doesn't work. pf4j won't create the extension object though it finds the plugin and extension classes. Stepping through the pf4j code it fails in AbstractExtensionFinder where the code checks if the created extension object can be cast to the extension interface. That check fails due to different class loaders. Here is the msg from console.

Extensions added by plugin 'simple-hello-plugin':
   com.curisprofound.plugins.simple.SimplePlugin$SimpleIdentityPlugin
2020-06-13 23:29:07.080  INFO 248 --- [  restartedMain] com.opencodez.RatingExtensions           : Extensions instances added by plugin 'simple-hello-plugin' for extension point 'com.curisprofound.plugins.PluginInterface':
2020-06-13 23:29:07.081 ERROR 248 --- [  restartedMain] org.pf4j.AbstractExtensionFinder         : Different class loaders: 'org.pf4j.PluginClassLoader@36903a10' (E) and 'org.springframework.boot.devtools.restart.classloader.RestartClassLoader@3a6dacb0' (EP)

I understand it is because of different class loaders for interface and extension object, but is there a resolution for this so I can debug my application within Eclipse. Do I have control over which classloader loads the interface class. Also, is this working in command line only by luck or will always work and it is an issue ONLY within Eclipse.

thanks

Decebal Suiu

unread,
Jun 15, 2020, 8:00:21 AM6/15/20
to pf4j
I understand it is because of different class loaders for interface and extension object

marge...@gmail.com

unread,
Jun 15, 2020, 11:22:04 PM6/15/20
to pf4j
Thanks. I should have mentioned in my original post. I did review those posts in github and included the 'provided' scope to the extension interface dependency in my plugin pom.xml as below. It still didn't help from within IDE. Again, It works just fine from command line (java -jar  etc..). Here is the POM extract for plugin project.
-----------------------------------------------------
        <dependency>
            <groupId>org.pf4j</groupId>
            <artifactId>pf4j</artifactId>
            <version>2.3.0</version>
<!-- !!! VERY IMPORTANT -->
<scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.curisprofound</groupId>
            <artifactId>shared-plugin-interfaces</artifactId>
            <version>1.1.0</version>
<!-- !!! VERY IMPORTANT -->
<scope>provided</scope>
        </dependency>
---------------------------

also checked the extensions.idx in the plugin jar and it contains 
# Generated by PF4J
com.curisprofound.plugins.simple.SimplePlugin$SimpleIdentityPlugin

Appreciate any other pointers. thanks.

Vladimir Shekhovtsov

unread,
Jul 21, 2021, 7:44:41 AM7/21/21
to pf4j
This is a belated answer, but hopefully it helps somebody. I had exactly the same problem. It happened to be caused by the dependency on spring-boot-devtools in application's pom.xml,
as the classloader  'org.springframework.boot.devtools.restart.classloader.RestartClassLoader'  is used by spring-boot-devtools to load application classes e.g. to implement live reloading,
And it was always different from the plugin's classloader. So eliminating the dependency on spring-boot-devtools in application's pom.xml resolved the issue.
Reply all
Reply to author
Forward
0 new messages