trung / InMemoryJavaCompiler

Utility class to compile java source code in memory
Apache License 2.0
266 stars 81 forks source link

Dependency of other jars or classes #21

Closed yafngzh closed 5 years ago

yafngzh commented 6 years ago

Execuse me, how can I depend on other jars and classes when using javacompiler? They are all included in my current process. Can I get the classpath variable in an elegant way?

ghost commented 5 years ago

The InMemoryJavaCompiler#useOptions may work.

https://github.com/trung/InMemoryJavaCompiler/blob/d84c404975dc308ee5a418c5af8a6629c5e6c995/src/main/java/org/mdkt/compiler/InMemoryJavaCompiler.java#L45

I found it when I read the compiler part of another project.

https://github.com/SpoonLabs/astor/blob/38765febb621aff921cedcc451509250e520b656/src/main/java/fr/inria/astor/core/manipulation/bytecode/compiler/tools/JavaXToolsCompiler.java#L46

https://github.com/SpoonLabs/astor/blob/38765febb621aff921cedcc451509250e520b656/src/main/java/fr/inria/astor/core/manipulation/bytecode/compiler/SpoonClassCompiler.java#L81