Setting run configurations and executing run option

How do set up new run configurations from Plugin code and execute the RUN function.

Basically my plugin takes parameters from User and those parameters will be used to run my java class

e.g: User enters Username , password and resource file.

i want to set run configurations as below.

Name : MyProgram

Main Class : com.myplugin.MyProgram

Program Arguments : -resource /home/abc/abc.resource -username abc@abc.com -password 123456

Workign diretory : /home/users/myplugin

Use classpath of module: myplugin

and Plugin should exeute RUN command and display results in Run window.

Thanks,

5 comments
Comment actions Permalink
Official comment

Sorry for late reply.

In order to create a run configuration call com.intellij.execution.RunManager#createConfiguration and then RunManager#addConfiguration to add the configuration to the list. If you want to create a Java Application run configuration pass instance of com.intellij.execution.application.ApplicationConfiguration to the method.

Method com.intellij.execution.runners.ExecutionUtil#runConfiguration can be used to start the configuration.

Comment actions Permalink

Thanks for the reply.

I have a follow up question.

I want to add ApplicationApplication however the jar which has the main class is bundled with plugin. So i assume in this case i need to setup -cp path of my plugin.jar 

Main Class : com.myplugin.MyProgram ( which is inside myplugin.jar )

Program Arguments : -resource /home/abc/abc.resource -username abc@abc.com -password 123456

Workign diretory : /home/users/myplugin

Use classpath of module: myplugin

Can you provide me any example which does something similar to above.

I'm not able to find any relevant example which adds ApplicationConfiguration in actionPerformed and sets MainClass, Program parameters, VM parameters etc..

 

 

0
Comment actions Permalink

ApplicationConfiguration doesn't allow to specify custom '-cp' argument, it'll automatically populate classpath accordingly to 'Use classpath of module' option.

See the sample code below:

RunManager runManager = RunManager.getInstance(e.getProject());
ApplicationConfiguration hello = new ApplicationConfiguration("Hello", e.getProject(), ApplicationConfigurationType.getInstance());
hello.MAIN_CLASS_NAME = "com.myplugin.MyProgram";
hello.PROGRAM_PARAMETERS = "-resource /home/abc/abc.resource -username abc@abc.com -password 123456";
hello.WORKING_DIRECTORY = "/home/users/myplugin";
hello.setModule(ModuleManager.getInstance(e.getProject()).findModuleByName("myplugin"));
RunnerAndConfigurationSettings configuration = runManager.createConfiguration(hello, hello.getFactory());
runManager.addConfiguration(configuration, false);
0
Comment actions Permalink

Thanks Nikolay.

 

How can i add Intellij Plugin related jars to current project.

Or when i install my Intellij Plugin current project will have access to jars which are bundled with my Intellij Plugin Jar.

 

In the end i want to something like this:

java -cp /myintellijplugin/lib/myplugintools.jar tools.scriptRunner -resource /home/abc/abc.resource -username abc@abc.com -password 123456
0
Comment actions Permalink

If that JAR is used from the project classes it's better to add as a library to corresponding module. In that case the JAR will be added to -cp argument when the run configuration is started, and you'll be also able to navigate to its classes from the editor. The simplest way to add a library is ModuleRootModificationUtil#addModuleLibrary method, you can use VfsUtil#getUrlForLibraryRoot to create URLs taken by this method.

0

Please sign in to leave a comment.