我编写了一个自定义maven插件,它扩展了axis2 wsdl2java插件,其概念是创建自定义生命周期,其中wsdl2java插件在执行我的自定义插件的目标之前执行。
调用自定义生命周期的代码如下:
lifecycle.xml
<lifecycles>
<lifecycle>
<id>custom-lifecycle</id>
<phases>
<phase>
<id>invoke</id>
<executions>
<execution>
<goals>
<goal>
org.apache.axis2:axis2-wsdl2code-maven-plugin:wsdl2code
</goal>
</goals>
<configuration>
<packageName>com.foo.myservice</packageName>
<wsdlFile>src/main/wsdl/myservice.wsdl</wsdlFile>
</configuration>
</execution>
</executions>
</phase>
</phases>
</lifecycle>
</lifecycles>
My Mojo is
/**
*
* @goal process
* @execute lifecycle="custom-lifecycle" phase="invoke"
*/
public class SampleMojo extends AbstractMojo
{
public void execute()
throws MojoExecutionException
{
//Code
}
}
问题:我想从我的自定义插件传递wsdl2java插件的参数(即,packagename,wsdlFile)。
是否可以将参数从我的Mojo发送到自定义生命周期?如果有,该怎么做?
Thanks in Advance
Aadhya
是的,这确实是可能的,并且可以通过使用@param用与xml参数相同的名称注释静态字段来实现,如下所示:
/**
* Package name - this is injected from the 'packageName' xml element
* @parameter
*/
private static String packageName;
/**
* WSDL File Location, populated from the 'wsdlFile' xml element
* @parameter
*/
private static String wsdlFile;
public void execute() throws MojoExecutionException, MojoFailureException {
//do stuff here with packageName and wsdlFile.
}
PS: Checkstyle有一个问题,@goal和@parameter -我不得不关闭Checkstyle使用//CSOFF: TreeWalker完全禁用它为这个类