Launch a Tomcat-based IntelliJ *configuration* from code

Answered

I have a Java application that depends on a Tomcat server running on the same box.  

  • I am able to detect whether the Tomcat server is up and running.
  • When it is not and I am running on a proper server I can use the following code to trigger the start of the Tomcat Windows Service:
String[] script = {"cmd.exe", "/c", "sc", "start", "tomcat10jobs" };
Process process = Runtime.getRuntime().exec(script);
  • But I need something equivalent when running inside of IntelliJ IDEA.  Because of how IDEA is designed, that means creating a launch Configuration and somehow launching it.  Manually it is no problem, I select the drop-down and hit Run or Debug.  But how do I launch it from Java code?... in a way that is equivalent to the above but instead of launching a Windows Service I launch the IntelliJ Configuration?
1
7 comments

Looks promising but I can't find the information for the Maven dependency needed to include these classes into my project.

Can you point me to it?

0

Hi Bruno,

I assume you develop an IntelliJ Platform plugin. Which classes do you mean?

0

The instructions in that second link are not 100% clear but seem to indicate that I need to use something like the snippet below.  So, I'd need access to RunnerAndConfigurationSettings, RunManager, ConfigurationType, Executor, ExecutorRegistry, ProgramRunnerUtil.  Maybe others.   It seems logical that these are in a library, and that the library can be included in my project through a Maven dependency.  Right?

So I need the info to add to my POM file so that Maven can download the library.

RunnerAndConfigurationSettings rcSettings = RunManager.getConfigurationSettings(ConfigurationType);
Executor executor = ExecutorRegistry.getExecutorById();
ProgramRunnerUtil.executeConfiguration(rcSettings, executor);
0

If you develop an IntelliJ Platform plugin and follow the process: https://plugins.jetbrains.com/docs/intellij/developing-plugins.html

then there is no need for additional dependencies.

It sounds like you want to use it in a regular project. If this is the case, then you can't, and this is the forum about IntelliJ Platform plugin development only, so we can't help you.

0

 

You are clearly not understanding my situation.  I will elaborate with some bolding to make the more important points clear.

I repeat, I am NOT creating a plugin.  I am creating normal applications.

  • The core application is a Spring Boot app whose normal execution is launched as a windows service.
  • The other applications are REST services deployed to a Tomcat server (not embedded - intentionally separate).
  • When running normally the core application relies on the Tomcat server and its REST apps to be deployed and running.  To avoid issues it probes to see if Tomcat is running and if not it uses the code in my initial post to start the Tomcat windows service.  The core application holds until the Tomcat server and REST service apps are running.   Then the core application resumes normal execution.  Of course if the Tomcat server was already up it simply continues normal execution without trying to launch Tomcat.

This post is about making the equivalent behavior to the above also work INSIDE IntelliJ so that developers can do their work with equal convenience.  That means that when probing the core application must start the desired Tomcat Run Configuration in IntelliJ debug mode as that is what is equivalent to starting that external Tomcat Windows service.

Based on your earlier reply, that needs to be done by executing those methods, which in turn REQUIRES that the library be available in the NORMAL APPLICAITION which is not a plugin.  For that I need the Maven POM dependencies (note:  Maven, not Gradle... I know that for plugins you expect people to use Gradle but this is NOT a plugin).

0

Hi Bruno,

This is a plugin development forum, so I assumed you develop a plugin, and it wasn't clearly confirmed until the last message.

IntelliJ Platform doesn't expose any API you can call to invoke run configuration from the external process. Also, you cannot utilize the classes from the docs in your application. The only solution I can think of involves creating a plugin that will expose an URL endpoint on the IntelliJ Platform built-in server, and will invoke a run configuration programmatically (in the way I linked) when the endpoint is called.

To expose an endpoint from IDE, implement the com.intellij.httpRequestHandler extension point (e.g., by extending RestService). For sample implementations, see the platform sources or IntelliJ Platform Explorer.

If your service has a name "myservice", it will be available under URL: http://127.0.0.1:63342/api.myservice.

The default port is 63342. If the default port is occupied, 63342 + n will be used (n < 20).

0

Please sign in to leave a comment.