0

My main.java file calls Tree.java which inturn calls TreeNode.java file. Whenever I compile for first time using main.java. everything runs perfect.but then if I made any changes in Treenode.java,it doesn't recompile it's class file and I get same output.

I studied that javac recompiles class file whenever source file has updated timestamp compared to class file.but it isn't working here.

I tried with IDE and it is updating perfectly.i am facing this issue only with cmd.please help with out with this issue.

  • Give us a more specific example. Tell us the *exact* `javac` command you run. And which files you changed how between those invocations. – Joachim Sauer Oct 23 '20 at 13:49
  • 3
    `javac` only compiles the files you call it with, it doesn't go looking for source files corresponding to the classes referenced in the file you've specified – Aaron Oct 23 '20 at 13:51
  • i just ran javac main.java which uses Tree.java which again uses TreeNode.java .i have added print statement in TreeNode.java but it doesn't show up in output when recompile main.java again.@JoachimSauer – rohith mudiraj Oct 23 '20 at 14:08
  • 1
    Yes, that is to be expected. You need to recompile each modified file. `javac` is a simple tool as far as developer's tools go, it's not aware of your different files or that you consider them part of a single project. You pass it a file, it compiles it. You need another file compiled? Make another call to `javac`. – Aaron Oct 23 '20 at 14:22
  • so what if i have hierarchical java files which calls each other and i made a change in leaf node java file.what shall i do to get the updated output ?@Aaron – rohith mudiraj Oct 23 '20 at 14:25
  • recompile the leaf node file, no need to recompile the main file if it hasn't changed, just execute it while making sure the updated class file for the leaf node is in its classpath – Aaron Oct 23 '20 at 14:26
  • really thanks for helping out man.i literally searched everywhere but didn't find enough info about this issue with javac . @Aaron – rohith mudiraj Oct 23 '20 at 14:34
  • You're welcome, glad I could help. – Aaron Oct 23 '20 at 14:40
  • This is one of the reasons people usually use a build tools like Maven, Gradle, or Ant to build Java projects. – Mark Rotteveel Oct 23 '20 at 14:59

0 Answers0