I wanted to invoke testng programmatically. Not eclipse plug-in.
I have associated \"testng-6.8.21.jar\" and running through eclipse and i ran below code:
As @sgrillon correctly pointed out, you need the correct Maven dependency, but also the shade plugin (https://maven.apache.org/plugins/maven-shade-plugin) to package a Uber-jar including all Maven dependencies for easy execution.
This is what should be included in your pom.xml
:
...
com.beust
jcommander
1.48
...
...
maven-compiler-plugin
3.1
1.8
org.apache.maven.plugins
maven-shade-plugin
2.3
package
shade
true
runnable
After you build the Maven package, you'll get your regular my-app-1.0-SNAPSHOT.jar
file and also a my-app-1.0-SNAPSHOT-runnable.jar
.
This is what you should run, with the command:
$ java -jar my-app-1.0-SNAPSHOT-runnable.jar
You can verify with this command:
$ jar tvf my-app-1.0-SNAPSHOT-runnable.jar
that the shaded jar contains the JCommander classes (and those of all the other Maven dependencies), while the regular one doesn't.