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 -password 123456

Workign diretory : /home/users/myplugin

Use classpath of module: myplugin

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


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.

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 -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..




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 -password 123456";
hello.WORKING_DIRECTORY = "/home/users/myplugin";
RunnerAndConfigurationSettings configuration = runManager.createConfiguration(hello, hello.getFactory());
runManager.addConfiguration(configuration, false);

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 -password 123456

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.


I tried to implement this example code but it fails because i can't find the ApplicationConfiguration.class which should be located in com.intellij.execution.application... this package is not included in the intellij plugin i try to create.

How could i import this package?


Hello Simon Höfle

Next time, please create a new thread instead of resuscitating the old one. ;-)


Answering your question - looks like you don't have a java plugin dependency specified in your Gradle configuration:

intellij {
// ...

plugins 'java'

.... so easy ;-)
thanks a lot!!


Please sign in to leave a comment.