devoured elysium
devoured elysium

Reputation: 105077

Is there any way to run Javac turning off code generation?

I'd be interested to know whether it's possible to run javac or an equivalent tool to just analyze the given Java source code without actually generating any code.

The usefulness would lie in being able to verify whether my Java code is correct without having to generate any .class output files.

Thanks

Upvotes: 3

Views: 156

Answers (2)

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103135

You may be interested in the Java Tools API. This API gives you programmatic control over the Java compiler and you can pretty much write a program to read and analyze a Java program. The API docs give an example of compiling a list of compiler error messages.

Upvotes: 4

emory
emory

Reputation: 10891

Yes, there is. I have never tried it, so I can not verify that this actually works, but ...

javac -proc:only

means that only annotation processing is done, without any subsequent compilation.

If that did not work, what is wrong with just using

javac -d /dev/null

Upvotes: 5

Related Questions