ClassCastException: org.jetbrains.idea.maven.server.MavenServerManager cannot be cast to org.jetbrains.idea.maven.server.MavenServerManager

I want to add some features on Maven Module to simplify creating maven project via the archetype which has a lot of required parameters.

I add maven plugin's jar into my plugin project as libs, and make classes extending MavenModuleBuilder and ModuleWizardStep(class who extends ModuleWizardStep is rewrited from SelectPropertiesStep)

Then, if I ran the plugin, and tried creating a project, a exception would be thrown:

[  52487]  ERROR - llij.ide.plugins.PluginManager - org.jetbrains.idea.maven.server.MavenServerManager cannot be cast to org.jetbrains.idea.maven.server.MavenServerManager
java.lang.ClassCastException: org.jetbrains.idea.maven.server.MavenServerManager cannot be cast to org.jetbrains.idea.maven.server.MavenServerManager
 at org.jetbrains.idea.maven.server.MavenServerManager.getInstance(MavenServerManager.java:114)
 at org.jetbrains.idea.maven.utils.MavenUtil.resolveMavenHomeDirectory(MavenUtil.java:541)
 at org.jetbrains.idea.maven.project.MavenEnvironmentForm.createUIComponents(MavenEnvironmentForm.java:120)
 at org.jetbrains.idea.maven.project.MavenEnvironmentForm.$$$setupUI$$$(MavenEnvironmentForm.java)
 at org.jetbrains.idea.maven.project.MavenEnvironmentForm.<init>(MavenEnvironmentForm.java:63)
 at com.cmbchina.ccd.pluto.cmbus.plugin.module.CmbusFrameworkSelectPropertiesStep.initComponents(CmbusFrameworkSelectPropertiesStep.java:53)
 at com.cmbchina.ccd.pluto.cmbus.plugin.module.CmbusFrameworkSelectPropertiesStep.<init>(CmbusFrameworkSelectPropertiesStep.java:49)
 at com.cmbchina.ccd.pluto.cmbus.plugin.module.CmbusFrameworkProjectModuleBuilder.createWizardSteps(CmbusFrameworkProjectModuleBuilder.java:31)
 at com.intellij.ide.util.newProjectWizard.StepSequence.addStepsForBuilder(StepSequence.java:61)
 at com.intellij.ide.projectWizard.ProjectTypeStep.<init>(ProjectTypeStep.java:238)
 at com.intellij.ide.projectWizard.NewProjectWizard.init(NewProjectWizard.java:50)
 at com.intellij.ide.projectWizard.NewProjectWizard.<init>(NewProjectWizard.java:39)
 at com.intellij.ide.actions.NewProjectAction.actionPerformed(NewProjectAction.java:30)

I guess that maven plugin used getInstance() metod at first, and MavenServerManager which is loaded into maven plugin's classloader became the singleton.
Then when my plugin try calling getInstance(), it tried returing current instance(whose class is in maven plugin's classloader) as a MavenServerManager(which is in my plugin's classloader)
So there can be a ClassCastException from MavenServerManager to MavenServerManager itself.

Classloader separetion is good if there is no dependencies between plugins, but what could I do if there is a dependency in this situation?
Does it means that I have to fork a private version for the maven plugin, in order to add features to extend it?

My Env:
[  52492]  ERROR - llij.ide.plugins.PluginManager - IntelliJ IDEA 14.1.4  Build #IU-141.1532.4
[  52493]  ERROR - llij.ide.plugins.PluginManager - JDK: 1.7.0_80
[  52494]  ERROR - llij.ide.plugins.PluginManager - VM: Java HotSpot(TM) 64-Bit Server VM
[  52494]  ERROR - llij.ide.plugins.PluginManager - Vendor: Oracle Corporation
[  52495]  ERROR - llij.ide.plugins.PluginManager - OS: Windows 7
[  52496]  ERROR - llij.ide.plugins.PluginManager - Last Action: NewProject

0
4 comments

Instead of adding the jars of the Maven plugin as libs, you need to add them to the classpath of the IntelliJ IDEA plugin SDK.

0

I removed libs and added those jars into SDK's classpath(Project Struct-> SDKs -> IntelliJ IDEA IU-141.1532.4 -> Classpath),
The compiling is ok, but it throw another exception when running:

[  47025]  ERROR - llij.ide.plugins.PluginManager - org/jetbrains/idea/maven/wizards/MavenModuleBuilder
java.lang.NoClassDefFoundError: org/jetbrains/idea/maven/wizards/MavenModuleBuilder
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:643)
 at com.intellij.util.lang.UrlClassLoader._defineClass(UrlClassLoader.java:259)
 at com.intellij.util.lang.UrlClassLoader.defineClass(UrlClassLoader.java:255)
 at com.intellij.util.lang.UrlClassLoader._findClass(UrlClassLoader.java:231)
 at com.intellij.ide.plugins.cl.PluginClassLoader.b(PluginClassLoader.java:124)
 at com.intellij.ide.plugins.cl.PluginClassLoader.a(PluginClassLoader.java:77)
 at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:66)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:278)
 at com.intellij.openapi.extensions.AbstractExtensionPointBean.findClass(AbstractExtensionPointBean.java:42)
 at com.intellij.openapi.extensions.AbstractExtensionPointBean.instantiate(AbstractExtensionPointBean.java:63)
 at com.intellij.ide.util.projectWizard.ModuleBuilderFactory.createBuilder(ModuleBuilderFactory.java:32)
 at com.intellij.ide.util.projectWizard.ModuleBuilder.getAllBuilders(ModuleBuilder.java:75)
 at com.intellij.ide.projectWizard.ProjectTypeStep.a(ProjectTypeStep.java:283)
 at com.intellij.ide.projectWizard.ProjectTypeStep.<init>(ProjectTypeStep.java:136)
 at com.intellij.ide.projectWizard.NewProjectWizard.init(NewProjectWizard.java:50)
 at com.intellij.ide.projectWizard.NewProjectWizard.<init>(NewProjectWizard.java:39)
 at com.intellij.ide.actions.NewProjectAction.actionPerformed(NewProjectAction.java:30)
 at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:182)
 at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter$1.run(ActionMenuItem.java:312)
 at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:958)
 at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:124)
 at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:282)
 at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
 at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:109)
 at com.intellij.ui.plaf.beg.BegMenuItemUI.a(BegMenuItemUI.java:512)
 at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:44)
 at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:532)
 at java.awt.Component.processMouseEvent(Component.java:6516)
 at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
 at java.awt.Component.processEvent(Component.java:6281)
 at java.awt.Container.processEvent(Container.java:2229)
 at java.awt.Component.dispatchEventImpl(Component.java:4872)
 at java.awt.Container.dispatchEventImpl(Container.java:2287)
 at java.awt.Component.dispatchEvent(Component.java:4698)
 at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
 at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
 at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
 at java.awt.Container.dispatchEventImpl(Container.java:2273)
 at java.awt.Window.dispatchEventImpl(Window.java:2719)
 at java.awt.Component.dispatchEvent(Component.java:4698)
 at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
 at java.awt.EventQueue.access$300(EventQueue.java:103)
 at java.awt.EventQueue$3.run(EventQueue.java:706)
 at java.awt.EventQueue$3.run(EventQueue.java:704)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
 at java.awt.EventQueue$4.run(EventQueue.java:720)
 at java.awt.EventQueue$4.run(EventQueue.java:718)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
 at com.intellij.ide.IdeEventQueue.e(IdeEventQueue.java:734)
 at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:565)
 at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.lang.ClassNotFoundException: org.jetbrains.idea.maven.wizards.MavenModuleBuilder PluginClassLoader[com.cmbchina.ccd.pluto.cmbus.plugin.api.extraction.idea, 1.0]
 at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:68)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
 ... 65 more

it still looks like a classloader issue?

0

Did you add the <depends> tag to your plugin.xml?

0

Yes, i forgot to add <depends>. And now, it works.
Thanks a lot.


----------------------------------
BTW, there is a wirzard problem(maybe a bug or a design issue) in maven plugin:
choose creating a maven project from an archetype ->
enter project groupid,artifactId then click next ->
add/edit some properties in the list the click next ->
click previous

all modification in the property list will disappear.

Usually, if there is not a lot of properties required in the archetype, it won't be a serious problem.
But, in my case, lots of properties need to be set, the "Previous" becomes a very serious problem for the users.

It's confirmed in IU14.1.4 and 15.0.2.

0

Please sign in to leave a comment.