我试图将maven插件的功能转移到独立的java命令行应用程序中。 maven插件正在使用maven plugin annotations,例如@Component
注释。
@Mojo( name = "customGoal" )
public class CustomMojo extends AbstractMojo {
@Component( hint = "customHint" )
private MyCustomComponent cmp;
public vodi execute() throws MojoExecutionException {
// Funcionality of my custom maven plugin
}
}
当maven插件启动时,带注释的对象cmp
将通过maven注入。类MyCustomComponent
也使用maven插件注释,例如@Requirement
:
@Component(role = MyCustomComponentInterface.class, hint = "customHint")
public class MyCustomComponent implements MyCustomComponentInterface {
@Requirement
private AnyRequiredObject obj;
@Requirement
privater OtherRequiredObject obj2;
// Funcionality
}
如何在独立的Java应用程序中实现相同的行为?有这种用例的解决方案吗?