public class MainClass {
public static void main(String [] args) throws ClassNotFoundException{
//String[] xyz = {"Client1"};
List<XmlSuite> suites = new ArrayList<XmlSuite>();
XmlSuite suite=new XmlSuite();
suite.setName("Demo");
XmlTest test=new XmlTest(suite);
List<String> groups=new ArrayList<String>();
for(String arg:args){
groups.add(arg);
}
List<XmlClass> classes =new ArrayList<XmlClass>();
System.out.println(Class.forName("TrailAndTest.TestClass"));
classes.add(new XmlClass(Class.forName("TrailAndTest.TestClass")));
test.setXmlClasses(classes);
test.setIncludedGroups(groups);
suites.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.run();
}
}
在我的代码中,我编写的公共类被定义为“公共类 Mainclass”,并且文件以名称 MainClass.java 保存当我尝试从命令提示符执行此代码时出现错误:
- C:\Selenium\Code\Test\src\TrailAndTest\Mainclass.java:13: 类 MainClass 是公共的,应该在名为 MainClass.java 的文件中声明公共类 MainClass ^ 1 错误
我执行的操作:
C:\Selenium\Code\Test>set path=%path%;"C:\Program Files\Java\jdk1.5.0_22\bin"
C:\Selenium\Code\Test>set CLASSPATh="C:\Selenium\Code\Test\bin;C:\Selenium\Code\ Test\Jars\selenium-2.25.0\libs\commons-logging-1.1.1.jar;C:\Selenium\Eclipse\ecl ipse-jee-indigo-win32-x86_64\eclipse\plugins\org.testng.eclipse_6.7.0.20120808_0 858\libtesting.jar;C:\Selenium\Eclipse\eclipse-jee-indigo-win32-x86_64\eclipse\p lugins\org.eclipse.wb.runtime.lib_1.5.0.r37x201206111201\lib\cglib-nodep-2.2.jar ;C:\Selenium\ExternalJar\selenium-server-standalone-2.21.0.jar;" C:\Selenium\Code\Test>javac -sourcepath "C:\Selenium\Code\Test\src" "C:\Seleniu m\Code\Test\src\TrailAndTest\Mainclass.java" -d "C:\Selenium\Code\Test\bin" C:\Selenium\Code\Test\src\TrailAndTest\Mainclass.java:13: class MainClass is pub lic, should be declared in a file named MainClass.java public class MainClass ^ 1 error C:\Selenium\Code\Test>