Need to start and stop appium server programatically

Hi i am trying to start and stop Appium server programmatically by following the steps mentioned in the below URL

but getting errors in all the steps…

kindly let us know if there is any other methods to do…

Kindly find the below URL for the error that we also get

You might have some setup issues, revise your setup. Node Instalation and configuration, Java_home and everything else.
Here is my implementation. I;m just calling the startServer method in @BeforeSuite and stopServer in @AfterSuite.
APPIUM_PORT and LOG_LEVEL are constants defined in .properties file. Replace it with 4723 and error/debug/info

private static AppiumDriverLocalService service;
private static Logger log = LogManager.getLogger(AppiumSetup.class.getName());

public static void startServer(){
	AppiumServiceBuilder builder;"Building and starting the server:");
	builder = new AppiumServiceBuilder();
	builder.withArgument(GeneralServerFlag.LOG_LEVEL, LogLevel);
	service = AppiumDriverLocalService.buildService(builder);
	service.start();"Server started on Port - " + APPIUM_PORT);

public static void stopServer() {
	try {"Trying to stop the server...");
		service.stop();"Success, Server stopped.");
	} catch (Exception e) {"Appium server could not be stopped.");

thank you @Zuceac when i tried the code than you mentioned with the changes i am getting error like below
Caused by: java.lang.NullPointerException: Unable to find executable for: cmd.exe

As I said, you might have configuration errors. Check them. Try to add cmd to your environment path.
Can you start appium manually from cmd?

@Zuzeac Thanks for your help. I could able to run appium manually from cmd and all my configurations are properly made. I figured that eclipse was not able to identify the path correctly, so adding the PATH in eclipse ease my work and the script is running.

I think, it would be good if you showed your configuration first. Anyway, here is another example: which I created some time ago

Refer this post:

Hi deepikathiru, is that possible for you to share you code? I met the same issue of getting below error.

java.lang.NullPointerException: Unable to find executable for: cmd.exe

Hi @Serena
AppiumDriverLocalService service;
service = new AppiumServiceBuilder().usingPort(port).build();

this is the code i use now for starting the server through cmd. If you still get Null pointer exception i suggest you to check the configuration of the IDE that you use.

hi, how to do it in javascript. Will be helpfull if anyone knows the solution