0

I'm trying to compile a .java file, and within this file there exists method calls to a variety of other .java files outside the directory of this .java file. I would like to keep these other .java files in different folders.

My question is just, how do I compile this .java file without having to have them in the same folder?

newuser
  • 17
  • 4
  • Use a build tool. Like: maven, gradle, ant or sbt. How are you currently building? And an example of the directory structure you're asking about would be helpful. – Elliott Frisch May 19 '20 at 23:41
  • Not sure what that really means, sorry im kind of new. I'm just compiling from the command line – newuser May 19 '20 at 23:42

1 Answers1

0

If class A references class B, but class B doesn't reference class A, then what you can do is compile class B, and put the class/jar on the classpath (using the -cp flag) when compiling class A. If A and B both reference each other, typically they must be compiled together. The exception is if A or B hasn't changed (i.e. a .class file exists) in which case you it works like the first example

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80