3

I have just written a Java multi-threaded program in Eclipse. It compiled fine and works like a charm.

However, as this is coursework we are required to ensure that it compiles in the command line using 'javac' otherwise we score ZERO!

So, some classes compile others don't. The error I'm getting is the following ( they are all similar just with different class names, this is one example)

GateRunnable.java:7: cannot find symbol
symbol  : class Station
location: class package.name.here.GateRunnable
    public GateRunnable(Station st) {
                        ^

Is this a javac issue? Any help appreciated.

Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54
Force444
  • 3,321
  • 9
  • 39
  • 77

3 Answers3

2

Your compile -classpath and/or -sourcepath is incomplete. The compiler doesn't know where to find class Station. Here is a related question that describes how to set the classpath to include all the classes you want.

Community
  • 1
  • 1
mbatchkarov
  • 15,487
  • 9
  • 60
  • 79
  • 1
    If you have circular dependencies (I hope not), you may take a look at the 'sourcepath' option. – Andy Nov 21 '12 at 21:40
  • Can't get it to work. My current directory is in the src folder where all my classes are. Assuming there are four named Class1.java , Class2.java and so on. How would you set the class/source path to include all of them? Thanks – Force444 Nov 21 '12 at 21:51
2

To solve the problem I was having, it was simply necessary to compile all classes by using the following command:

javac *.java 

which compiles all java files in the directory.

Force444
  • 3,321
  • 9
  • 39
  • 77
0

have you compiled every .java file in your folder/packages? if not, then do so. Eclipse usually does that for you, but within the terminal it's you taking the responsibility of compiling every part of the code.

  • 1
    ...and you need to start compiling your .java files who don't have any dependency on your own java classes before the others. Also, if you use any third party library, don't forget do set the classpath using the -classpath command line option (http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html). – Pedro Boechat Nov 21 '12 at 21:34
  • No, provided it can find the dependencies javac will compile them if they need to be (I do this using javac all day every day for work). – Lawrence Dol Nov 21 '12 at 21:42