How to programmatically change IDEA project classpath?
Hi! I need to progarmmatically add/remove entries to/from IDEA project classpath from within plugin. Is it possible to do that, using Open API or Psi API? ProjectRootManager has methods to retrieve classpath entries, but does not provide a way to manipulate it. I hope I overlooked the API call for that. It would be nice to be able to do so, otherwise users have to go ProjectOptions?/Paths/Classpath/Browse to find the correct entries, whereas this information is available in the plugin code.
Thanks for any ideas!
Pavlin
请先登录再写评论。
Hi,
I push this message to the top, even it's over a year old.
I've got the same question :
Is there a way to manipulate the project classpath programmatically (add/remove) ?
I also searched the OpenApi and the forum for an answer with no success.
Regards
Christopher
You may look into ModuleRootManager interface. There is no sample of such
usage in our samples but I can post you a few lines doing something like
that.
final ModuleRootManager rootManager =
ModuleRootManager.getInstance(myModule);
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
final Library.ModifyableModel libraryModel =
rootModel.getModuleLibraryTable().createLibrary().getModifyableModel();
libraryModel.addRoot(libClassesRoot, OrderRootType.CLASSES);
libraryModel.addRoot(libSrcRoot, OrderRootType.SOURCES);
libraryModel.commit();
rootModel.commit();
--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"
"Christopher Rammensee" <no_mail@jetbrains.com> wrote in message
news:31388752.1063868116637.JavaMail.itn@is.intellij.net...
>
(add/remove) ?
>
>
Thanks for the quick answer !
But I'm having problems with your solution
I can't find this class anywhere. It's not included in the openApi.jar of #929. Even the class Library is missing there. It only exists in idea.jar.
Am I missing something ?
Regards
Oh, I see. It's in fact a problem with ZKM obfuscator - it incorrectly
handles inner classes in our Open API. We should not make it an inner class.
We'll fix this for the next build.
--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"
"Christopher Rammensee" <no_mail@jetbrains.com> wrote in message
news:19237915.1063882555354.JavaMail.itn@is.intellij.net...
>
#929. Even the class Library is missing there. It only exists in idea.jar.
>
>
Also as a workaround until we fix it you can use "Library$ModifyableModel"
as class name.
--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"
"Christopher Rammensee" <no_mail@jetbrains.com> wrote in message
news:19237915.1063882555354.JavaMail.itn@is.intellij.net...
>
#929. Even the class Library is missing there. It only exists in idea.jar.
>
>
Hi Valentin,
thank you for the tip!
I tried the lines you posted and at first it seams to work, but later IDEA couldn't find the classes contained in the just added librarty. I've tried to add the same library using the standard IDEA project settings dialog and I got two entries for the same library, where the one which was added using OPEN API dind't work (removing it changed nothing at all) and the one added from the IDEA dialog was correct. Restarting IDEA didn't help with that.
The exact lines of code I use are:
No exception was thrown.
Is there anything I do wrong?
Thanks!
Pavlin