How to provide an interface to JavaCompiler when compiling a source file dynamically?

后端 未结 3 1892
难免孤独
难免孤独 2020-12-15 11:51

I\'m trying to compile and load a class at runtime, without knowing the package of the class. I do know that the class should comply with an interface, and the location of t

相关标签:
3条回答
  • 2020-12-15 12:46

    Not sure if this is what you're looking for but, as mentioned by @Phil here, you could try to pass a classpath argument in your compiler.run method.

    0 讨论(0)
  • 2020-12-15 12:49

    Have you considered generating your class with javassist or something like that?

    0 讨论(0)
  • 2020-12-15 12:50

    It seems likely that the compiler.run() is running externally and needs the class path to be set. Have you tried to pass it a suitable class path setting using the last parameter args to the run() call? Perhaps that's why ToolProvider.getSystemToolClassLoader().

    This stackoverflow post might also help you.

    0 讨论(0)
提交回复
热议问题