我是Windows的命令行运行Java的新手,无法让我的程序运行。概述,这正是我想要做的:
运行两个.java文件,TestCase1.java和UniversalVariables.java
合并多个外部jar文件
从命令行执行所有这些操作
TestCase1.java具有所有正常运行的代码,而UniversalVariables.java几乎只有一些数据,所以不要让那里的所有内容混淆你。
应该注意的是,我正在使用Selenium并通过Eclipse运行它。
这是TestCase1.java:
package NSSR;
import com.thoughtworks.selenium.*;<br>
import org.junit.After;<br>
import org.junit.Before;<br>
import org.junit.Test;<br>
//Create new NSSR
public class TestCase1 extends SeleneseTestCase {
public static void main(String[] args) {
TestCase1 tc1 = new TestCase1();
try {
tc1.setUp();
tc1.testTestCase1();
tc1.tearDown();
} catch (Exception e) {
}
}
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox",
UniversalVariables.baseAddress);
selenium.start();
}
@Test
public void testTestCase1() throws Exception {
selenium.open(UniversalVariables.loginPage);
selenium.type("name=USERNAME", UniversalVariables.username);
selenium.type("name=PASSWORD", UniversalVariables.password);
selenium.click("link=Submit");
selenium.waitForPageToLoad("60000");
selenium.open("/itg/dashboard/app/portal/PageView.jsp?IS_WINDOID=N");
selenium.click("link=Create");
selenium.click("link=Request");
selenium.waitForPageToLoad("30000");
selenium.select("name=REQUEST_TYPE_CREATE",
"label=Non-Standard Service");
selenium.click("css=span.secBtn > a");
selenium.waitForPageToLoad("30000");
String title = UniversalVariables.getRandomTitle();
String req = UniversalVariables.Requestor;
String dept = UniversalVariables.reqDept;
String desc = UniversalVariables.getRandomDescription();
String date = UniversalVariables.getRandomDate();
System.out.println(title);
System.out.println(req);
System.out.println(dept);
System.out.println(desc);
System.out.println(date);
selenium.type("id=REQ.DESCRIPTION", title);
selenium.type("id=REQ.P.REQUESTORAC_TF", req);
selenium.select("id=REQ.P.REQUESTOR_DEPT", dept);
selenium.type("id=REQ.P.DETAIL_DESC", desc);
selenium.type("REQ.P.REQ_COMPL_DATE", date);
selenium.click("link=Submit");
selenium.waitForPageToLoad("30000");
selenium.refresh();
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
package NSSR;
import com.thoughtworks.selenium.*;<br>
import org.junit.After;<br>
import org.junit.Before;<br>
import org.junit.Test;<br>
//Create new NSSR
public class TestCase1 extends SeleneseTestCase {
public static void main(String[] args) {
TestCase1 tc1 = new TestCase1();
try {
tc1.setUp();
tc1.testTestCase1();
tc1.tearDown();
} catch (Exception e) {
}
}
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox",
UniversalVariables.baseAddress);
selenium.start();
}
@Test
public void testTestCase1() throws Exception {
selenium.open(UniversalVariables.loginPage);
selenium.type("name=USERNAME", UniversalVariables.username);
selenium.type("name=PASSWORD", UniversalVariables.password);
selenium.click("link=Submit");
selenium.waitForPageToLoad("60000");
selenium.open("/itg/dashboard/app/portal/PageView.jsp?IS_WINDOID=N");
selenium.click("link=Create");
selenium.click("link=Request");
selenium.waitForPageToLoad("30000");
selenium.select("name=REQUEST_TYPE_CREATE",
"label=Non-Standard Service");
selenium.click("css=span.secBtn > a");
selenium.waitForPageToLoad("30000");
String title = UniversalVariables.getRandomTitle();
String req = UniversalVariables.Requestor;
String dept = UniversalVariables.reqDept;
String desc = UniversalVariables.getRandomDescription();
String date = UniversalVariables.getRandomDate();
System.out.println(title);
System.out.println(req);
System.out.println(dept);
System.out.println(desc);
System.out.println(date);
selenium.type("id=REQ.DESCRIPTION", title);
selenium.type("id=REQ.P.REQUESTORAC_TF", req);
selenium.select("id=REQ.P.REQUESTOR_DEPT", dept);
selenium.type("id=REQ.P.DETAIL_DESC", desc);
selenium.type("REQ.P.REQ_COMPL_DATE", date);
selenium.click("link=Submit");
selenium.waitForPageToLoad("30000");
selenium.refresh();
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
这是UniversalVariables.java:
package NSSR;
import java.util.*;
public class UniversalVariables {
public static String baseAddress = "******";
public static String loginPage = "******";
public static String username = "******";
public static String password = "******";
public static ArrayList<String> NSSR_Titles = new ArrayList<String>(NSSR_Titles());
public static String Requestor = "******";
public static String reqDept = "Shared Services";
public static ArrayList<String> NSSR_Descriptions = new ArrayList<String>(NSSR_Descriptions());
public static ArrayList<String> NSSR_Dates = new ArrayList<String>(NSSR_Dates());
public static Random randy = new Random();
public static int num;
public static String getRandomTitle() {
num = randy.nextInt(NSSR_Titles.size());
return NSSR_Titles.get(num);
}
public static String getRandomDescription() {
num = randy.nextInt(NSSR_Descriptions.size());
return NSSR_Descriptions.get(num);
}
public static String getRandomDate() {
num = randy.nextInt(NSSR_Dates.size());
return NSSR_Dates.get(num);
}
public static ArrayList<String> NSSR_Titles() {
ArrayList<String> list = new ArrayList<String>();
for(int i = 1; i < 11; i++)
list.add("Title " + i);
return list;
}
public static ArrayList<String> NSSR_Descriptions() {
ArrayList<String> list = new ArrayList<String>();
for(int i = 1; i < 11; i++)
list.add("Description " + i);
return list;
}
public static ArrayList<String> NSSR_Dates() {
ArrayList<String> list = new ArrayList<String>();
for(int i = 1; i < 13; i++)
for(int j = 1; j < 29; j++)
for(int k = 13; k < 100; k++) {
String str = i + "/" + j + "/20" + k;
list.add(str);
}
return list;
}
}
这是我放入命令行的内容(这些是我使用的所有jar文件。我知道它不漂亮......忍受我。):
package NSSR;
import java.util.*;
public class UniversalVariables {
public static String baseAddress = "******";
public static String loginPage = "******";
public static String username = "******";
public static String password = "******";
public static ArrayList<String> NSSR_Titles = new ArrayList<String>(NSSR_Titles());
public static String Requestor = "******";
public static String reqDept = "Shared Services";
public static ArrayList<String> NSSR_Descriptions = new ArrayList<String>(NSSR_Descriptions());
public static ArrayList<String> NSSR_Dates = new ArrayList<String>(NSSR_Dates());
public static Random randy = new Random();
public static int num;
public static String getRandomTitle() {
num = randy.nextInt(NSSR_Titles.size());
return NSSR_Titles.get(num);
}
public static String getRandomDescription() {
num = randy.nextInt(NSSR_Descriptions.size());
return NSSR_Descriptions.get(num);
}
public static String getRandomDate() {
num = randy.nextInt(NSSR_Dates.size());
return NSSR_Dates.get(num);
}
public static ArrayList<String> NSSR_Titles() {
ArrayList<String> list = new ArrayList<String>();
for(int i = 1; i < 11; i++)
list.add("Title " + i);
return list;
}
public static ArrayList<String> NSSR_Descriptions() {
ArrayList<String> list = new ArrayList<String>();
for(int i = 1; i < 11; i++)
list.add("Description " + i);
return list;
}
public static ArrayList<String> NSSR_Dates() {
ArrayList<String> list = new ArrayList<String>();
for(int i = 1; i < 13; i++)
for(int j = 1; j < 29; j++)
for(int k = 13; k < 100; k++) {
String str = i + "/" + j + "/20" + k;
list.add(str);
}
return list;
}
}
编译得很好。然后我把它放到命令行中:
然后是错误:
>javac -classpath C:\JAR\junit-4.0.jar;C:\JAR\junit-4.0-src.jar;C:\JAR\selenium-java-c
lient-driver.jar;C:\JAR\selenium-java-client-driver-sources.jar;C:\JAR\selenium-
java-client-driver-tests.jar;C:\JAR\selenium-java-client-driver-test-sources.jar
;C:\JAR\selenium-server.jar;C:\JAR\selenium-server-coreless.jar;C:\JAR\selenium-
server-sources.jar;C:\JAR\selenium-server-standalone-2.24.1.jar; NSSR\TestCase1.
java NSSR\UniversalVariables.java
>java NSSR.TestCase1
仅供参考,这是我的CLASSPATH:
。; C:\ Program Files \ Java \ jre6 \ lib \ ext \ QTJava.zip; C:\ WINDOWS \ system32 \ java.exe \ lib; C:\ Program Files \ IBM \ RationalSDLC \ ClearQuest \ cqjni。罐; C:\ JAR的* .jar
非常感谢任何帮助!
答案 0 :(得分:3)
你需要将jars作为参数放到java
,与javac
传递的一样。
答案 1 :(得分:1)
java -classpath "C:\JAR\junit-4.0.jar;C:\JAR\junit-4.0-src.jar;C:\JAR\selenium-java-client-driver.jar;C:\JAR\selenium-java-client-driver-sources.jar;C:\JAR\selenium-java-client-driver-tests.jar;C:\JAR\selenium-java-client-driver-test-sources.jar;C:\JAR\selenium-server.jar;C\JAR\selenium-server-coreless.jar;C:\JAR\selenium-server-sources.jar;C:\JAR\selenium-server-standalone-2.24.1.jar" NSSR.TestCase1
应该做你想做的事。 java
还需要知道在哪里找到库。它不存储在引用类文件中(并且不应该存储,因为它只适合您自己的系统)