How to copy jar in libs folder using Intellij plugin development APIs

I am developing intellij plugin, on click of menu option it should copy jar to libs folder of select project. kindly provide any link or code refrence how I can implement this.

10 comments
Comment actions Permalink
jar is on this path "project_name\resources\raw\xyz.jar" and using below code to get that jar as inputsream but getting "NULL"

ClassLoader CLDR = this.getClass().getClassLoader();
InputStream is =  CLDR.getResourceAsStream("raw/xyz.jar");
0
Comment actions Permalink

Hello,

You can obtain a file handle via regular java file api like below

 
final File file = new File(project.getBasePath(), "resources/raw/xyz.jar");
if (file.isFile()) {
  FileUtil.copy(file, destination);
}

Denis

0
Comment actions Permalink
 
We are developing a intellij plugin which has feature to add jar file to the selected project's libs folder. 
 
I have .jar file in 'raw' folder of my plugin project.
 
project.getBasePath() will give path of slected project. 
 
Where as I want to copy jar file from installed plugin to selected project's libs folder.
  
0
Comment actions Permalink

So, why don't you copy that jar to the selected lib folder?

Denis

0
Comment actions Permalink

I want to do it through right clicking on project and select plugin option 'Add Jar'.
Because the required jar is provided through this plugin only.
The same thing I have implemented for eclipse plugin.

0
Comment actions Permalink

Sorry but it's hard to guess what did you do in eclipse plugin.

Could you be more specific in your questions because for now it looks like you ask to implement a plugin.

Denis

0
Comment actions Permalink

post.png

I want to give user this option using plugin for rapid development.
When user will right click on project and select this option then jar will be added on "selected_project\app\libs" this path
I hope now you understood my question.

0
Comment actions Permalink

What is 'user will right on project'? Do you mean project view or project settings or something else?

And yes, your question still lacks the details.

Denis

0
Comment actions Permalink

finally below code works.

PluginId runtimePluginId = PluginManager.getPluginByClassName("com.company.AnyClassInYourPlugin");
IdeaPluginDescriptor runtimePlugin = PluginManager.getPlugin(runtimePluginId);
File yourJar = new File(runtimePlugin.getPath().getAbsolutePath(), "your-file.jar");
Given any class that's contained in your plugin, 
the API allows you to retrieve a plugin descriptor for that plugin,
which then allows you to get the absolute path to the plugin or any jar related to it.
0
Comment actions Permalink

@Vibha, thanks for the above code. can you please post the code to paste the jar in lib of a project.

0

Please sign in to leave a comment.