1

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.

Rohhit
  • 722
  • 3
  • 12
  • 25

1 Answers1

2

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.

Anubhav Mishra
  • 106
  • 2
  • 17
  • Hi anubhav thanks for your help. Its working... but my eclipse is showing "TesNG" class is deprecated... Any other class i can use instead of "TestNG" ? – Rohhit May 13 '16 at 13:27
  • Hi Rohit, Can you share the error or the warnings which you are getting so that I may be able to help you better. In the meanwhile for further information on TestNG you can click [here.](http://testng.org/doc/documentation-main.html#running-testng-programmatically) – Anubhav Mishra May 16 '16 at 06:06
  • Hi thanks, I am getting strike out on TestNG class [TestNG testng=new TestNG();] Saying that it is deprecated. Any new class which we can use? – Rohhit May 16 '16 at 13:29
  • Actually code is working fine.. but dont want to use deprecated class :) – Rohhit May 16 '16 at 13:32