1
votes

I am learning webdriver and I have created one project with TestNg. I have several classes in my package under src folder. No class contains public static void main(....). i.e[Entry Point]

My question is :

Can we create Runnable / Executable jar file through eclipse for projects like this[project without main method]. I searched on many sites but unfortunately didnt get solution.

Please suggest me some links OR The way by which we can do this.

1

1 Answers

2
votes

To create a jar file of the TestNG without main method you have to create another class which contain main method.

Suppose you have a TestNG file name as Sample.java, in the same package create one more class as ExecutableRar and write the below code :

public class ExecutableRar {

public static void main(String[] args) {
    TestNG testng = new TestNG();
     Class[] classes = new Class[]{Sample.class};
     testng.setTestClasses(classes);
     testng.run();

}

Now you can run this class as a Java Application. Then right click on the package --> Export --> Java --> Runnable jar File --> select ExecutableRar in launch configuration --> Browse the file location and enter the name of the file in Export Destination --> Finish.

Please let me know if you are having any issues.