Search code examples
antbuildsublimetext2targets

Specify and switch between ant targets in sublime text 2


I´m using Sublime Text 2 together with the ant build system. CTRL+B works perfectly fine to start the build with the default target. However my question is, is there a ways to define different ant build targets and have a mechanism to switch between them easily?

I thought about creating additional custom build commands for each target - for example like "clean". It works, but that is not the best approach in my eyes because you have to go to "Tools > Build System > Ant (clean)" and hit CTRL+B afterwards.


Solution

  • Save this build file as *.sublime-build file in the Packages/User folder

    {
        "selector": "source.java",
        "cmd": ["ant"],
    
        "variants": [
    
            { "cmd": ["solve_world_hunger"],
              "name": "Solve World Hunger"
            },
    
            { "cmd": ["ant", "clean"],
              "name": "Run"
            }
        ]
    }
    
    • Default target will build on ctrl+b
    • The cmd named Run in the variants array will run on ctrl+shift+b
    • Any cmd in the variants array can be run via the command palette by searching for name. i.e. hit ctrl+shift+p and type Solve World Hunger to run the solve world hunger command.