How to Start/Kill appium server within java code

How to start Appium Server programmatically Start / Stop

You can try something like this:

AppiumServiceBuilder builder = new AppiumServiceBuilder();
            builder.withIPAddress("0.0.0.0");
            builder.usingAnyFreePort();
            builder.withLogFile(new File("./logs/appiumLogs.log"));
            service = AppiumDriverLocalService.buildService(builder);
            service.start();


            //service.stop(); //to stop