Java Code to start Appium server on Mac

For continuous integration, we want everything to be integrated and well coupled. One problem statement arises where we need to keep appium server in launched state before executing our suite.

 Though, it's not a problem anymore. All you need to do is just install ant and put this piece of code before invocating iOSDriver.  Here I'm saying iOSdriver because I'm using default xcode simulator. For android, if you use genymotion then you need write a function that launch genymotion as well. This is altogether a different problem statement and we will discuss in a separate thread.

Feel free to share, like or reply to me in case you face any difficulty while setting up. I myself (at my level best)  or other developers reading this blog will surely answer your questions.

    private  Process process;
    private  String APPIUMSERVERSTART = "/usr/local/bin/appium";   

    public void startAppiumServer() throws IOException, InterruptedException {

        CommandLine command = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");
        command.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js", false);
        command.addArgument("--address", false);
        command.addArgument("--port", false);
        command.addArgument("--full-reset", false);
        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
        DefaultExecutor executor = new DefaultExecutor();
        executor.execute(command, resultHandler);

            System.out.println("Appium server started");

    public  void stopAppiumServer() throws IOException {
        String[] command ={"/usr/bin/killall","-KILL","node"};
        System.out.println("Appium server stop");


  1. Could you show how should we code when the Appium and iOS app is installed on Mac and Eclipse and java code is existing on windows machine

  2. Hi Ashish,

    This is a good question. I have done this on all-Mac or all-Windows setup. I'll try this and let you know. Meanwhile, others can share thoughts if they have came across this problem.


  3. Many classes like CommandLine ,DefaultExecuteResultHandler are not getting imported from the packages that I have , can u please tell me the packages used to import all the classes used in your program.

  4. what are all need to import for this?

  5. i used the same code and i still unable to start iOSdriver. can you please help in this?

  6. For me its throwing unreachable browser exception.. please help!

  7. I'm sorry to all those whom I could not respond.

  8. @Unknown : Please share the complete logs. Also share the code if you have done any changes at your part.

    1. I switched to AppiumDriverLocalService class to launch the appium automatically but still stuck with the error:
      Here is my sample code:

      service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingPort(0).usingDriverExecutable(new File("path to node")).withAppiumJS(new File("path to appium.js")));


Recent Posts