I seem to have found the solution after a bit of googling.
(经过一番谷歌搜索后,我似乎已经找到了解决方案。)
This works fine in Eclipse (Juno). (这在Eclipse(Juno)中工作正常。)
Say, you have a TestNG file named 'Tests.java'.
(假设您有一个名为“ Tests.java”的TestNG文件。)
As you rightly pointed out, there won't be a class with main method. (正如您正确指出的那样,不会有带有main方法的类。)
So, we have to create a new Java class file under the same package. (因此,我们必须在相同的程序包下创建一个新的Java类文件。)
Let us name it 'MainOne.java'. (让我们将其命名为“ MainOne.java”。)
This will have a class with main method. (这将有一个带有main方法的类。)
Here is the code you need:
(这是您需要的代码:)
import com.beust.testng.TestNG;
public class MainOne {
public static void main(String[] args) {
TestNG testng = new TestNG();
Class[] classes = new Class[]{Tests.class};
testng.setTestClasses(classes);
testng.run();
}
Run the 'MainOne.java' as a Java application.
(作为Java应用程序运行“ MainOne.java”。)
Then right click on the package -> Export -> Runnable Jar [Choose 'MainOne' as Launch Configuration] -> Finish. (然后右键单击程序包->导出->可运行的Jar [选择'MainOne'作为启动配置]->完成。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…