无法为 webdriver+TestNg 项目创建可执行 jar,该项目不包含任何 class 中的主要方法
Not able to create executable jar for webdriver+TestNg project which does not contain main method in any class
我正在学习 webdriver,我已经用 TestNg 创建了一个项目。
我的包中有几个 classes 在 src 文件夹下。
没有 class 包含 public static void main(....)。即[入口点]
我的问题是:
对于这样的项目[没有main方法的项目],我们可以通过eclipse创建Runnable / Executable jar文件吗?我搜索了很多网站,但不幸的是没有得到解决方案。
请给我一些链接或我们可以做到这一点的方法。
要创建一个没有 main 方法的 TestNG jar 文件,您必须创建另一个包含 main 方法的 class。
假设你有一个名为 Sample.java 的 TestNG 文件,在同一个包中再创建一个 class 作为 ExecutableRar 并编写以下代码:
public class ExecutableRar {
public static void main(String[] args) {
TestNG testng = new TestNG();
Class[] classes = new Class[]{Sample.class};
testng.setTestClasses(classes);
testng.run();
}
现在您可以 运行 这个 class 作为 Java 应用程序。然后右击包 --> Export --> Java --> Runnable jar File --> select ExecutableRar in launch configuration --> Browse the file location and enter the name of the file在导出目标 --> 完成。
如果您有任何问题,请告诉我。
我正在学习 webdriver,我已经用 TestNg 创建了一个项目。 我的包中有几个 classes 在 src 文件夹下。 没有 class 包含 public static void main(....)。即[入口点]
我的问题是:
对于这样的项目[没有main方法的项目],我们可以通过eclipse创建Runnable / Executable jar文件吗?我搜索了很多网站,但不幸的是没有得到解决方案。
请给我一些链接或我们可以做到这一点的方法。
要创建一个没有 main 方法的 TestNG jar 文件,您必须创建另一个包含 main 方法的 class。
假设你有一个名为 Sample.java 的 TestNG 文件,在同一个包中再创建一个 class 作为 ExecutableRar 并编写以下代码:
public class ExecutableRar {
public static void main(String[] args) {
TestNG testng = new TestNG();
Class[] classes = new Class[]{Sample.class};
testng.setTestClasses(classes);
testng.run();
}
现在您可以 运行 这个 class 作为 Java 应用程序。然后右击包 --> Export --> Java --> Runnable jar File --> select ExecutableRar in launch configuration --> Browse the file location and enter the name of the file在导出目标 --> 完成。
如果您有任何问题,请告诉我。