IntelliJ IDEA: Run Batch script before and after Run/Debug Configuration

10,613

There is no way to run batch script directly in IDEA and it's also not possible to make a sequence of actions before run in IDEA 11.

In IDEA 12 it will be possible to specify multiple actions to perform before run, this way you can create a Maven goal that will restart Tomcat (by running batch script or some other way) and in Before Launch list specify 2 actions: kill running Tomcat process (which can be another Maven goal, another Run configuration or Ant task) and run the build (Maven goal). Here is how this UI looks like in IDEA 12:

Before Launch

When you run this configuration, it will kill Tomcat, perform the build and restart Tomcat.

It should also work if you chain multiple Run configurations with the Run Another Configuration Before Launch step.

IDEA 12 is planned for the end of 2012, but first EAP versions will be available in several weeks.


Another solution would be to use a single Maven goal with Mojo Executor or Ant task that will perform all the 3 actions.

Share:
10,613

Related videos on Youtube

Robotnik
Author by

Robotnik

[ Software Engineer ] [ Moderator ] [ Volunteer ] [ Gamer ] [ Father ] [ He/Him ] Hello, my name is Ryan, I'm an Elected Moderator on Arqade, the video gaming Stack Exchange site. I'm a full-stack Software Engineer with years of experience in Web and App development. My current tech stack consists primarily of HTML5/JS (React, Typescript), as well as AWS Microservices, Postgres, and a bit of C#. Over the years I've worked with a multitude of technologies: ASP.NET, Android/iOS development, Xbox One and Windows 10 Apps (Both XAML and HTML based ones), Java and so on. I also volunteer in Environment & Sustainability groups in my local area (if you're reading this and into that sort of stuff, you should join the Sustainable Living SE!). I enjoy many video, board and card games, as well as D&D as both DM and player. I'm currently playing in a Star Wars 5e campaign, as a naive Droid Engineer: TA-1! Check it out here: Star Wars D&D. Find me on: YouTube - A Pinch of Salt (Group channel) - game-play and gaming/tech podcasts with friends YouTube - RobotnikPlays - (Personal channel) - game-play, achievements, tricks and techniques, time trials, and commentary on gaming in general. Steam - My primary gaming platform Discord - A Pinch of Salt - Video gaming, D&D, tech and lots more.

Updated on July 14, 2022

Comments

  • Robotnik
    Robotnik almost 2 years

    Background:

    I have a Run config that runs a maven build. I already have a Context Path set up to look at the Target Directory of the Build directory, so I don't have to manually copy the war file over every time I run a build.

    What I would like is for my build config to automatically kill the running tomcat process, run the build, and (if successfull) restart tomcat.

    Problem:

    I'd like to simply call the start/stop tomcat batch files before and after the build, but I've hit two snags:

    • In the Build Config->Before Launch section, there's no option to execute a batch script
    • There doesn't seem to be an "After build" section to complete Phase 2

    Is there some way of enabling these options for my current build configuration (via a plugin or similar)?

    -OR-

    Is it possible to have build configurations run in sequence (one after the other) and is there a plugin or something to create a batch script build configuration?