从Maven插件访问项目类 [英] Access project classes from a maven plugin
问题描述
我正在制作一个在测试阶段运行的Maven插件,在使用我的插件的项目的pom.xml配置中,我设置了一个类规范名称,我想使用该类规范名称从我的插件中运行该类,基本上,我正在通过插件从项目内部动态加载类.
I'm making a maven plugin that run in test phase, in pom.xml configuration of a project that uses my plugin, I'm setting a class canonical name that I want to use to run that class from my plugin, basically I'm making a way to have a dynamic class loading of classes inside the project from my plugin.
Class clazz = Class.forName("... class from pom.xml ...")
当我运行它时,会收到预期的"ClassNotFoundException",似乎类加载器不相同或未共享.
When I run it I receive the expectable "ClassNotFoundException", seems the class loader are not the same or not shared.
有办法做到吗?像是从项目中捕获类加载器,还是通过将依赖项注入到我的插件中来接收它?最好的方法是什么?
There is a way to do it? Like capture the class loader from the project or receive it by dependency injection into my plugin? What is the best way?
推荐答案
我们可以在mojo中使用Hibernate实现,作为实现它的参考:
We can use the Hibernate implementation in mojo can be used as a reference to make it: