Volodya Lombrozo
Volodya Lombrozo

Reputation: 3454

How to Compile Java Classes at Runtime Without Saving to the Filesystem?

I'm developing a Java application where I need to compile Java code provided as a String at runtime. I know that using the JavaCompiler API from javax.tools allows for dynamic compilation, but most examples involve writing the source code to a .java file on the filesystem.

(As suggested here, for instance.)

I want to avoid any disk I/O operations. Is it possible to compile Java classes entirely in memory, without saving the source code or compiled class files to the filesystem?

I don't need to load the compiled class into a class loader — I only need the raw compiled bytecode. Any code examples or guidance on achieving in-memory compilation would be greatly appreciated!

Upvotes: 0

Views: 60

Answers (0)

Related Questions