【问题标题】:How to create folder for generated sources in Maven?如何在 Maven 中为生成的源创建文件夹?
【发布时间】:2011-04-26 21:16:50
【问题描述】:

我必须使用 wsimport 生成源,并且我假设它应该转到 /target/generated-sources/wsimport 而不是 /src/main/java。

问题是 wsimport 需要在执行之前创建目标文件夹并且它失败了。我可以先使用任何 maven 插件创建该目录吗?我可以使用 ant 来完成,但我更喜欢将其保存在 POM 中。

【问题讨论】:

    标签: maven-2 jax-ws wsimport


    【解决方案1】:

    尝试使用build helper pluginadd source 目标:

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>build-helper-maven-plugin</artifactId>
      <executions>
        <execution>
          <id>add-source</id>
          <phase>generate-sources</phase>
          <goals>
            <goal>add-source</goal>
          </goals>
          <configuration>
            <sources>
              <source>${basedir}/target/generated/src/wsimport</source>
            </sources>
          </configuration>
        </execution>
      </executions>
    </plugin>  
    

    【讨论】:

    • 这不能回答问题(也没有必要)
    • 但对有类似问题的人有帮助。
    【解决方案2】:

    我必须使用 wsimport 生成源,并且我假设它应该转到 /target/generated-sources/wsimport 而不是 /src/main/java。

    这是一个正确的假设。

    问题是 wsimport 需要在执行之前创建目标文件夹并且它失败了。我可以先使用任何 maven 插件创建该目录吗?我可以使用 ant 来完成,但我更喜欢将其保存在 POM 中。

    我从来没有注意到这个问题(并且会认为它是一个错误,插件必须处理这些事情)。

    奇怪的是WsImportMojo 似乎通过调用File#mkdirs() 来做必须做的事情:

    public void execute()
        throws MojoExecutionException
    {
    
        // Need to build a URLClassloader since Maven removed it form the chain
        ClassLoader parent = this.getClass().getClassLoader();
        String originalSystemClasspath = this.initClassLoader( parent );
    
        try
        {
    
            sourceDestDir.mkdirs();
            getDestDir().mkdirs();
            File[] wsdls = getWSDLFiles();
            if(wsdls.length == 0 && (wsdlUrls == null || wsdlUrls.size() ==0)){
                getLog().info( "No WSDLs are found to process, Specify atleast one of the following parameters: wsdlFiles, wsdlDirectory or wsdlUrls.");
                return;
            }
            ...
         }
         ...
    }

    您能否展示您如何调用插件及其配置?

    【讨论】:

    • 我正在使用 exec-maven-plugin 执行 wsimport,这就是问题所在。我切换到 jaxws-maven-plugin,现在它对我来说很好。
    • 可能除了在 generate-sources 阶段处理每个 WSDL 之后编译源。我无法将 -Xnocompile 参数传递给 wsimport,但它仍然有效。
    • @Lorean 不确定,但 1. 您应该能够使用 args 可选参数声明可选的 wsimport 命令行选项 2. 插件似乎默认通过 -Xnocompile。
    猜你喜欢
    • 2013-10-19
    • 2011-11-01
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多