Masood
Posts: 9
Nickname: shooter
Registered: Jul, 2003
|
|
Re: compile error
|
Posted: Jul 15, 2003 9:03 PM
|
|
Here is the code that I am trying to compile. Assignment class is calling (or refrencing) class Test. Which is in a c:\code directroy. I have also included the code for Test.java
If I add set classpath=c:\code;. Do I still have to compile using the follwoing commands
C:\java>javac -classpath c:\code Assignment.java C:\java\java -classpath c:\code Assignment
I tried to compile using w/o classpath option and I got an error. Then whats point of setting classpath in autoexec.bat!!!
I hope this helps you guys. Thanks for your help.
//: c03:Assignment.java // Assignment with objects is a bit tricky. // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 // www.BruceEckel.com. See copyright notice in CopyRight.txt. import com.bruceeckel.simpletest.*;
class Number { int i; }
public class Assignment { static Test monitor = new Test(); public static void main(String[] args) { Number n1 = new Number(); Number n2 = new Number(); n1.i = 9; n2.i = 47; System.out.println("1: n1.i: " + n1.i + ", n2.i: " + n2.i); n1 = n2; System.out.println("2: n1.i: " + n1.i + ", n2.i: " + n2.i); n1.i = 27; System.out.println("3: n1.i: " + n1.i + ", n2.i: " + n2.i); monitor.expect(new String[] { "1: n1.i: 9, n2.i: 47", "2: n1.i: 47, n2.i: 47", "3: n1.i: 27, n2.i: 27" }); } }
**********************************************************
//: com:bruceeckel:simpletest:Test.java // Simple utility for testing program output. Intercepts // System.out to print both to the console and a buffer. // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 // www.BruceEckel.com. See copyright notice in CopyRight.txt. package com.bruceeckel.simpletest; import java.io.*; import java.util.*; import java.util.regex.*;
public class Test { // Bit-shifted so they can be added together: public static final int EXACT = 1 << 0, // Lines must match exactly AT_LEAST = 1 << 1, // Must be at least these lines IGNORE_ORDER = 1 << 2, // Ignore line order WAIT = 1 << 3; // Delay until all lines are output private String className; private TestStream testStream; public Test() { // Discover the name of the class this // object was created within: className = new Throwable().getStackTrace()[1].getClassName(); testStream = new TestStream(className); } public static List fileToList(String fname) { ArrayList list = new ArrayList(); try { BufferedReader in = new BufferedReader(new FileReader(fname)); try { String line; while((line = in.readLine()) != null) { if(fname.endsWith(".txt")) list.add(line); else list.add(new TestExpression(line)); } } finally { in.close(); } } catch (IOException e) { throw new RuntimeException(e); } return list; } public static List arrayToList(Object[] array) { List l = new ArrayList(); for(int i = 0; i < array.length; i++) { if(array instanceof TestExpression) { TestExpression re = (TestExpression)array; for(int j = 0; j < re.getNumber(); j++) l.add(re); } else { l.add(new TestExpression(array.toString())); } } return l; } public void expect(Object[] exp, int flags) { if((flags & WAIT) != 0) while(testStream.numOfLines < exp.length) { try { Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } } List output = fileToList(className + "Output.txt"); if((flags & IGNORE_ORDER) == IGNORE_ORDER) OutputVerifier.verifyIgnoreOrder(output, exp); else if((flags & AT_LEAST) == AT_LEAST) OutputVerifier.verifyAtLeast(output, arrayToList(exp)); else OutputVerifier.verify(output, arrayToList(exp)); // Clean up the output file - see c06:Detergent.java testStream.openOutputFile(); } public void expect(Object[] expected) { expect(expected, EXACT); } public void expect(Object[] expectFirst, String fname, int flags) { List expected = fileToList(fname); for(int i = 0; i < expectFirst.length; i++) expected.add(i, expectFirst); expect(expected.toArray(), flags); } public void expect(Object[] expectFirst, String fname) { expect(expectFirst, fname, EXACT); } public void expect(String fname) { expect(new Object[] {}, fname, EXACT); } } ///:~
|
|