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(AppiumServiceBuilder.java:397)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:332)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildService(AppiumDriverLocalService.java:76)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService(AppiumDriverLocalService.java:72)
at com.appium.common.CheckInRealDevice.f(CheckInRealDevice.java:30)
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(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.validator.routines.InetAddressValidator
at java.net.URLClassLoader.findClass(Unknown 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 - https://stackoverflow.com/questions/8496494/running-command-line-in-java