Pregunta

I'm using tools from the compiler API (javax.tools.JavaCompiler) to dynamically generated Java bytecode. I build source code and use API to compile it, then use it via reflexion.

That's perfectly fine as long as I only try te generated non-public classes. If i do, I get a "class MyClass is public, should be declared in a file named MyClass.java" which is perfectly normal, its not compiled from a Java file.

I'm looking for a way to bypass this error, haven't find any in Java options nor in the API.

¿Fue útil?

Solución

Check this article: Create class from string

For me using "string:///" resolve this issue.

as this is described here http://www.javablogging.com/dynamic-in-memory-compilation/

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top