How to run appium server programmatically (appium 1.6.5)

Hello, everyone
I have tried the code below to run the appium server programmatically.But not able to do so

AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();
** service.start();**

getting error:

java.lang.NoClassDefFoundError: org/apache/commons/validator/routines/InetAddressValidator
at io.appium.java_client.service.local.AppiumServiceBuilder.createArgs(
at org.openqa.selenium.remote.service.DriverService$
at io.appium.java_client.service.local.AppiumDriverLocalService.buildService(
at io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService(
at com.appium.common.CheckInRealDevice.f(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(
at org.testng.internal.Invoker.invokeMethod(
at org.testng.internal.Invoker.invokeTestMethod(
at org.testng.internal.Invoker.invokeTestMethods(
at org.testng.internal.TestMethodWorker.invokeTestMethods(
at org.testng.TestRunner.privateRun(
at org.testng.SuiteRunner.runTest(
at org.testng.SuiteRunner.runSequentially(
at org.testng.SuiteRunner.privateRun(
at org.testng.SuiteRunnerWorker.runSuite(
at org.testng.TestNG.runSuitesSequentially(
at org.testng.TestNG.runSuitesLocally(
at org.testng.TestNG.runSuites(
at org.testng.remote.RemoteTestNG.initAndRun(
at org.testng.remote.RemoteTestNG.main(
Caused by: java.lang.ClassNotFoundException: org.apache.commons.validator.routines.InetAddressValidator
at Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 30 more

@Aleksei Need some help if you know this how to solve.Thanks …

@suryakanta939 i am starting appium in command line. just like a command in terminal. how you installed appium server?

@Aleksei I am also starting through the command line i.e for Appium 1.6.5 m just writing the command ’ Appium’ and it will start the Appium server. But I just wanted to run automatically through the java coding .I don’t want to do manually through the command line.

About installation process : I did it by using the universal command like “npm install -g Appium”

@suryakanta939 i am starting this “automatically” through code :slight_smile: not manually. there are many ways to execute programmatically. mine favorite is through ProcessBuilder.

@Aleksei today the whole day I tried a different way to run it programmatically but didn’t get any solution for that… tried everything …:slightly_frowning_face:

If you could help with your sample code then it will be greate… :relieved:…is there any extra jar need to add or what?

@suryakanta939 more then 3 ways including processbuilder -