Add a jar (library) to a Module's Class Path (Libraries)

Hi all,

My plugin should add a given jar to the module's classpath...

I wrote this code on the plugin's button's actionPerfomed:



The doesnt run with the following exception...
I can't understand the exception at all (NullPointers...)
does anyone have a clue of what i'm missing?
Thanks very much for your time and help


(LibraryOrderEntryImpl.java:41) at com.intellij.openapi.roots.impl.RootModelImpl.addLibraryEntry(RootModelImpl.java:139) at com.intellij.openapi.samples.HelloWorldAction.actionPerformed(HelloWorldAction.java:44) at com.intellij.openapi.actionSystem.impl.ActionButton.performAction(ActionButton.java:23) at com.intellij.openapi.actionSystem.impl.ActionButton.processMouseEvent(ActionButton.java:15) at java.awt.Component.processEvent(Component.java:5253) at java.awt.Container.processEvent(Container.java:1966) at java.awt.Component.dispatchEventImpl(Component.java:3955) at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822) at java.awt.Container.dispatchEventImpl(Container.java:2010) at java.awt.Window.dispatchEventImpl(Window.java:1774) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:54) at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:1) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:112) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110) [ 49753] ERROR - ots.impl.LibraryOrderEntryImpl - Assertion failed [ 49768] ERROR - ots.impl.LibraryOrderEntryImpl - IntelliJ IDEA 5.0.2 Build #3542 [ 49768] ERROR - ots.impl.LibraryOrderEntryImpl - JDK: 1.5.0_04 [ 49768] ERROR - ots.impl.LibraryOrderEntryImpl - VM: Java HotSpot(TM) Client VM [ 49768] ERROR - ots.impl.LibraryOrderEntryImpl - Vendor: Sun Microsystems Inc. [ 49768] ERROR - ots.impl.LibraryOrderEntryImpl - OS: Windows XP [ 49768] ERROR - ots.impl.LibraryOrderEntryImpl - Last Action: Actions.ActionsPlugin.HelloWorld [ 49768] ERROR - ots.impl.LibraryOrderEntryImpl - Assertion failed java.lang.Throwable at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78) at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:86) at com.intellij.openapi.roots.impl.LibraryOrderEntryImpl.(LibraryOrderEntryImpl.java:41) at com.intellij.openapi.roots.impl.RootModelImpl.addLibraryEntry(RootModelImpl.java:139) at com.intellij.openapi.samples.HelloWorldAction.actionPerformed(HelloWorldAction.java:44) at com.intellij.openapi.actionSystem.impl.ActionButton.performAction(ActionButton.java:23) at com.intellij.openapi.actionSystem.impl.ActionButton.processMouseEvent(ActionButton.java:15) at java.awt.Component.processEvent(Component.java:5253) at java.awt.Container.processEvent(Container.java:1966) at java.awt.Component.dispatchEventImpl(Component.java:3955) at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822) at java.awt.Container.dispatchEventImpl(Container.java:2010) at java.awt.Window.dispatchEventImpl(Window.java:1774) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:54) at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:1) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:112) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110) java.lang.NullPointerException at com.intellij.openapi.roots.impl.LibraryOrderEntryImpl.getLibraryLevel(LibraryOrderEntryImpl.java:88) at com.intellij.openapi.roots.impl.LibraryOrderEntryImpl.c(LibraryOrderEntryImpl.java:42) at com.intellij.openapi.roots.impl.LibraryOrderEntryImpl.(LibraryOrderEntryImpl.java:30) at com.intellij.openapi.roots.impl.RootModelImpl.addLibraryEntry(RootModelImpl.java:139) at com.intellij.openapi.samples.HelloWorldAction.actionPerformed(HelloWorldAction.java:44) at com.intellij.openapi.actionSystem.impl.ActionButton.performAction(ActionButton.java:23) at com.intellij.openapi.actionSystem.impl.ActionButton.processMouseEvent(ActionButton.java:15) at java.awt.Component.processEvent(Component.java:5253) at java.awt.Container.processEvent(Container.java:1966) at java.awt.Component.dispatchEventImpl(Component.java:3955) at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822) at java.awt.Container.dispatchEventImpl(Container.java:2010) at java.awt.Window.dispatchEventImpl(Window.java:1774) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:54) at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:1) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:112) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110) [ 49768] ERROR - com.intellij.ide.IdeEventQueue - Error during dispatching of java.awt.event.MouseEvent[MOUSE_RELEASED,(582,60),button=1,modifiers=Button1,clickCount=1] on frame0 [ 49768] ERROR - com.intellij.ide.IdeEventQueue - IntelliJ IDEA 5.0.2 Build #3542 [ 49768] ERROR - com.intellij.ide.IdeEventQueue - JDK: 1.5.0_04 [ 49768] ERROR - com.intellij.ide.IdeEventQueue - VM: Java HotSpot(TM) Client VM [ 49768] ERROR - com.intellij.ide.IdeEventQueue - Vendor: Sun Microsystems Inc. [ 49768] ERROR - com.intellij.ide.IdeEventQueue - OS: Windows XP [ 49768] ERROR - com.intellij.ide.IdeEventQueue - Last Action: Actions.ActionsPlugin.HelloWorld [ 49768] ERROR - com.intellij.ide.IdeEventQueue - Error during dispatching of java.awt.event.MouseEvent[MOUSE_RELEASED,(582,60),button=1,modifiers=Button1,clickCount=1] on frame0 java.lang.NullPointerException at com.intellij.openapi.roots.impl.LibraryOrderEntryImpl.getLibraryLevel(LibraryOrderEntryImpl.java:88) at com.intellij.openapi.roots.impl.LibraryOrderEntryImpl.c(LibraryOrderEntryImpl.java:42) at com.intellij.openapi.roots.impl.LibraryOrderEntryImpl.(LibraryOrderEntryImpl.java:30) at com.intellij.openapi.roots.impl.RootModelImpl.addLibraryEntry(RootModelImpl.java:139) at com.intellij.openapi.samples.HelloWorldAction.actionPerformed(HelloWorldAction.java:44) at com.intellij.openapi.actionSystem.impl.ActionButton.performAction(ActionButton.java:23) at com.intellij.openapi.actionSystem.impl.ActionButton.processMouseEvent(ActionButton.java:15) at java.awt.Component.processEvent(Component.java:5253) at java.awt.Container.processEvent(Container.java:1966) at java.awt.Component.dispatchEventImpl(Component.java:3955) at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822) at java.awt.Container.dispatchEventImpl(Container.java:2010) at java.awt.Window.dispatchEventImpl(Window.java:1774) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:54) at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:1) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:112) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110) ]]>


Again, thank you

Eyal

4 comments

Hello Eyal,

EK> The doesnt run with the following exception...
EK> I can't understand the exception at all (NullPointers...)
EK> does anyone have a clue of what i'm missing?

If I understand correctly, the call to rootModel.addLibraryEntry() is not
needed at all. When you call getModuleLibraryTable().createLibrary(), the
library returned from this method is already added to the module library
table.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

(SOLVED)
Hi Dmitry,

First, Thank you for the quick reply.

I followed your suggestion and commented only the line before last:


And it worked , which is good on its own...





Now to fine-tune my solution, I removed the library name argument from the createLibrary method and dynamically retireved the module.


So, Check out this complete solution:


Thanks again and I hope it will help the others..

Eyal

0

Dmitry,


I wonder:
Is there some place where this specific subject is documented?
It was pretty hard to go from example to example on the web and to try my way out...
The Javadocs help very little since large parts of them are empty...

I there some sort oh IDEA OenAPI Tutorial?
Am I missing some trivial resource? :)


Eyal

0

Hello Eyal,

EK> I wonder:
EK> Is there some place where this specific subject is documented?
EK> It was pretty hard to go from example to example on the web and to
EK> try my way out...
EK> The Javadocs help very little since large parts of them are empty...
EK> I there some sort oh IDEA OenAPI Tutorial?
EK> Am I missing some trivial resource? :)

Not really. We do have some overview documentation (some of which will be
new in release 5.1), but it mostly covers introductory stuff. There is no
overview documenation covering more advanced API parts like module/library
management.

As for javadocs, we've spent quite a lot of time on javadocs in 5.0.1/5.0.2
releases, and we plan to expand the javadoc coverage further in the 6.0 release.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Please sign in to leave a comment.