Adding Jar/zip file to module libraries

Hi Guys,

I am a newbie to this plugin development. This is what, I want to do.

I need to write a plugin action which will add a given jar/zip file to the module classpath.

The action should automatically navigate to
Module settings -> Libraries -> Add Jar/Directory

and display the added jar/zip file in the module settings window.

Please let me know if there is any Open API class/method which will do this or let me know if there is any code sample available.

Thanks in advance,

Siddique

1 comment

Hello Siddique,

SH> I am a newbie to this plugin development. This is what, I want to
SH> do.
SH>
SH> I need to write a plugin action which will add a given jar/zip file
SH> to the module classpath.
SH>
SH> The action should automatically navigate to Module settings ->
SH> Libraries -> Add Jar/Directory
SH>
SH> and display the added jar/zip file in the module settings window.
SH>
SH> Please let me know if there is any Open API class/method which will
SH> do this or let me know if there is any code sample available.

There is no OpenAPI that will let you show the dialogs, but there is OpenAPI
that will let you add the .jar file if you provide your own user interface.
The code to do so looks like the following:

ModifiableRootModel rootModel = ModuleManager.getInstance(myModule).getModifiableModel();
Library library = rootModel.getModuleLibraryTable().createLibrary(myLibraryName);
library.getModifiableModel().addRoot(myJarUrl, OrderRootType.CLASSES);

I haven't actually tested this code, so if you run into any problems, feel
free to ask for more help. :)

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


0

Please sign in to leave a comment.