0

Is there a way to have javac only check a Java file for errors, but without compiling it to a class file? I'm only interested in checking whether the file has syntax errors and so on. I don't want the compiled class file.

hugomg
  • 68,213
  • 24
  • 160
  • 246
  • 2
    `javac MyClass.java && rm MyClass.class`? – Silvio Mayolo Sep 20 '22 at 14:46
  • 1
    I'm not sure javac can do this. Is producing the class file a problem? – Thomas Sep 20 '22 at 14:46
  • Not a big deal, other than the waste of cpu and disk space. Is there a least a way to tell it to pipe the class file straight to /dev/null, so I don't have to do a separate `rm` command? – hugomg Sep 20 '22 at 14:52
  • Btw, you could try another approach e.g. Eclipse JDT, the `JavaCompiler` class or some other syntax checker (depending on your needs you could also try to use ANTLR with a [Java grammar](https://github.com/antlr/grammars-v4/tree/master/java/java)). – Thomas Sep 20 '22 at 14:53
  • You try this -> javac -Werror filename.java but only problem is it will stop compilation if there are any error and warnings as well. – Umesh Sulakude Sep 20 '22 at 15:09

0 Answers0