将参数从 mojo 传递到自定义生命周期

发布于 2024-11-24 18:04:05 字数 1403 浏览 0 评论 0原文

我编写了一个自定义 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> 

我的 Mojo 是

/**
 * 
 * @goal process
 * @execute lifecycle="custom-lifecycle" phase="invoke"
 */
public class SampleMojo extends AbstractMojo
{
  public void execute()
    throws MojoExecutionException
  {
    //Code
  }
}

问题:我想从我的自定义插件传递 wsdl2java 插件的参数(即packagename、wsdlFile)。

是否可以将参数从我的 Mojo 发送到自定义生命周期?如果是的话该怎么办呢?

提前致谢

Aadhya

i have written a custom maven plugin which extends the axis2 wsdl2java plugin with the concept of creating custom lifecycle where the wsdl2java plugin is executed before goal of my custom plugin is executed.

The code for invoking the custom lifecycle is as follows.

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
  }
}

Problem:I want to pass the parameters of wsdl2java plugin (i.e,packagename,wsdlFile) from my custom plugin.

Is it possible to send the parameters from my Mojo to custom lifecycle? If so how to do it?

Thanks in Advance

Aadhya

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开柳相依 2024-12-01 18:04:05

是的,这确实是可以的,是通过用@param注释与xml参数同名的static字段来实现的,如下:

/**
 * 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 - 我必须使用 //CSOFF: TreeWalker 关闭 checkstyle 以完全禁用该类。

Yes, this is indeed possible, and is achieved by annotating static fields with the same name as the xml parameter with @param as follows:

/**
 * 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 has a problem with @goal and @parameter - I had to turn off checkstyle using //CSOFF: TreeWalker to disable it completely for this class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文