简体   繁体   English

在Eclipse中运行TestNG脚本的“找不到主类”错误

[英]“Could not find main class” error running TestNG script in Eclipse

I am trying to run a Selenium Web-Driver TestNG script in Eclipse. 我正在尝试在Eclipse中运行Selenium Web-Driver TestNG脚本。 I am getting the error shown below. 我收到下面显示的错误。

TestNG运行错误

I have tried changing preferences, checking/unchecking "use project testNG jar", messing with the build path, and recreating the project. 我尝试更改首选项,选中/取消选中“使用项目testNG jar”,弄乱构建路径,然后重新创建项目。 Can anyone please help me solve this problem so I can continue creating awesome scripts using TestNG? 谁能帮助我解决这个问题,以便我继续使用TestNG创建出色的脚本?

Your problem, based on Unsupported major.minor version 51.0 is wrong Java version. 您的问题基于Unsupported major.minor version 51.0是错误的Java版本。 The library you are using is compiled in one version, and you are using a different one (most probably, or definitely) you are using a lower version. 您正在使用的库是在一个版本中编译的,而您正在使用的是另一个版本(很可能是,或者肯定是),您是在使用较低的版本。

Version 51.0 refers to Java 7. I'd say the library you are using is Java 7 and yours is lower... To change this, go to: 版本51.0指的是Java7。我想说您正在使用的库是Java 7,而您使用的是较低的库。要更改此库,请转到:

Window -> Preferences -> Java -> Compiler 

And set the Compiler compliance level higher, at least 1.7 (ie Java 7). 并将Compiler compliance level设置为更高,至少为1.7 (即Java 7)。 If that's not an option, install a newer Java JDK (pref 1.8, that can, if you wish, also compile to Java 7). 如果不是这样,请安装较新的Java JDK(1.8版或更高版本,如果愿意,还可以编译为Java 7)。

Unsupported major.minor version 5{1,2,..}.0 (copied from https://stackoverflow.com/a/11432195/928952 ) 不支持的major.minor版本5 {1,2,..}。0 (从https://stackoverflow.com/a/11432195/928952复制)

J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

A more elaborative explanation of updating the JDK Eclipse is using: 更新JDK Eclipse的详细说明使用:

project -> properties -> java build path-> Add Library -> JRE System Library-> Installed JREs -> Add(unless jdk* is already in the list, then select that and go to next post -> standard VM -> Directory button -> browse to the location where you installed the JDK. Inside that directory you see a couple of folders, including bin and lib. 项目->属性-> Java构建路径->添加库-> JRE系统库->已安装JRE->添加(除非列表中已经存在jdk *,然后选择该内容,然后转到下一篇文章->标准VM->目录按钮->浏览至JDK的安装位置,在该目​​录中,您可以看到几个文件夹,包括bin和lib。
Make sure you select the parent directory of them. 确保选择它们的父目录。 Click OK. 单击确定。 You'll then see a list of .jars under JRE system libraries (must!) -> hit finish. 然后,您将在JRE系统库下看到一个.jars列表(必须!)-> hit finish。 Select the checkbox next to jdk1.8*. 选中jdk1.8 *旁边的复选框。 Press OK then finish. 按确定,然后完成。
Now you've got the right Java version in the Build Path... Now we have to make sure that becomes the compiler Now we're back at the properties, Go to Java Compiler, make sure enable project specific settings is turned off. 现在您已经在Build Path中找到了正确的Java版本...现在我们必须确保它成为编译器现在我们回到属性,转到Java Compiler,确保启用特定于项目的设置已关闭。 Click Configure Workspace Settings.... set the Compliance level: 1.8 -> apply (you get a message on compiler settings changed rebuild blablabla hit yes) then ok, then ok again... 单击“配置工作区设置...”。设置合规性级别:1.8->应用(更改编译器设置后,您会收到一条消息,请重新生成blablabla,单击“是”),然后单击确定,然后再次确定...

Eclipse is given strange error on not finding libs 没有找到库,Eclipse遇到奇怪的错误

You can try deleting the .project and .classpath files in the root of your project. 您可以尝试删除项目根目录中的.project和.classpath文件。 Delete the project from workspace (don't delete your source, backup first)... then reimport the project... might be that eclipse has configured something that doesn't exist anymore... helps me fix some dubious errors... 从工作区中删除项目(不要删除源文件,请先备份)...然后重新导入项目...可能是因为eclipse配置了不再存在的内容...帮助我修复了一些可疑的错误。 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM