ExecutionEnvironment (@NotNull Project project, @NotNull ExecuteRunConfigurationTask task, @Nullable Executor executor) { ApplicationConfiguration applicationConfiguration = (ApplicationConfiguration)task.getRunProfile(); ConfigurationFactory configurationFactory = new MavenExecConfigurationFactory(applicationConfiguration); String mainClassName = applicationConfiguration.getMainClassName(); if (isEmpty(mainClassName)) { return null; } Module module = applicationConfiguration.getConfigurationModule().getModule(); if (module == null) { return null; } MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(module); if (mavenProject == null) { return null; } //todo: Should be merged with MavenRunConfiguration RunnerAndConfigurationSettings runnerAndConfigurationSettings = RunManager.getInstance(project).createConfiguration(applicationConfiguration.getName(), configurationFactory); MyExecRunConfiguration mavenRunConfiguration = (MyExecRunConfiguration)runnerAndConfigurationSettings.getConfiguration(); mavenRunConfiguration.setBeforeRunTasks(applicationConfiguration.getBeforeRunTasks()); copyLogParameters(applicationConfiguration, mavenRunConfiguration); MavenRunnerParameters runnerParameters = mavenRunConfiguration.getRunnerParameters(); runnerParameters.setWorkingDirPath(mavenProject.getDirectory()); runnerParameters.setPomFileName(mavenProject.getFile().getName()); JavaParameters javaParameters = new JavaParameters(); JavaParametersUtil.configureConfiguration(javaParameters, applicationConfiguration); ParametersList execArgs = new ParametersList(); execArgs.addAll(javaParameters.getVMParametersList().getList()); execArgs.add("-classpath"); execArgs.add("%classpath"); execArgs.add(mainClassName); execArgs.addParametersString(applicationConfiguration.getProgramParameters()); String execExecutable = getJdkExecPath(applicationConfiguration); if (execExecutable == null) { throw new RuntimeException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable")); } String workingDirectory = ProgramParametersUtil.getWorkingDir(applicationConfiguration, project, module); List<String> goals = runnerParameters.getGoals(); if (isNotEmpty(workingDirectory)) { goals.add("-Dexec.workingdir=" + workingDirectory); } goals.add("-Dexec.args=" + execArgs.getParametersString()); goals.add("-Dexec.executable=" + toSystemDependentName(execExecutable)); goals.add("exec:exec"); if (executor == null) { executor = DefaultRunExecutor.getRunExecutorInstance(); } return new ExecutionEnvironmentBuilder(project, executor) .runProfile(mavenRunConfiguration) .runnerAndSettings(ProgramRunner.getRunner(executor.getId(), runnerAndConfigurationSettings.getConfiguration()), runnerAndConfigurationSettings) .build(); }