java - Maven - 部署 :deploy-file over series of files within ${project. build.directory} (target/)

标签 java maven deployment wsdl kuali

简要介绍一下我的情况 - 我正在处理一个代码库,该代码库具有 JAX-WS 注释接口(interface)/类,我们从中生成代码优先 wsdls。我们正在使用 CXF 的 cxf-java2ws-plugin 在构建时在 Maven 中生成 wsdls,以包含在为每个模块生成的 .jar 中。

我们要做的是将这些 wsdl 文件部署到 maven 存储库,因为 maven 存储库可以充当

  • 临时服务存储库(如描述的 here )
  • 为客户提供一种使用 cxf codegen plugin 的简便方法通过指向 wsdl 的 maven 坐标而不是自己管理 wsdl 文件

到目前为止,我得到的是一个 pom 文件,它使用 dependency:unpack-dependencies 将项目中的所有 wsdl 文件放入此模块 ${project.build.directory} 中的一个目录中(通常称为目标/给那里的每个人)。

我不知道如何做的是遍历每个文件并调用 deploy:deploy-file每个 wsdl 上的 mojo。我真的想自动化部署这些 wsdl 文件的过程,而不是让任何人手动部署它们,我在这里有什么选择?

为了完整起见,这里是 pom 文件:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>rice</artifactId>
        <groupId>org.kuali.rice</groupId>
        <version>2.0.0-m7-SNAPSHOT</version>
    </parent>
    <artifactId>rice-dist-wsdl</artifactId>
    <name>Rice WSDL Distributions</name>
    <packaging>pom</packaging>

    <properties>
        <wsdl.location>${project.build.directory}/wsdl</wsdl.location>
    </properties>


    <!-- Depends on all API modules and modules that generate or contain wsdls -->
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-core-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-kew-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-kim-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-krms-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-ksb-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-shareddata-api</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-wsdls</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includes>**\/*.wsdl</includes>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

将 wsdl 推送到 target/wsdl 中(它们包含在 wsdl/中,在每个被依赖的 .jar 中):

[whaley@sunspot ~/Repositories/Kuali/rice/dist-wsdl] 
> find . -iname '*.wsdl' | head -3
./target/wsdl/CampusService.wsdl
./target/wsdl/CountryService.wsdl
./target/wsdl/CountyService.wsdl

解决方案

认为我实现的与 Ryan Steward 提供的已接受答案不同,我接受了他的答案,因为它促使我​​写了自己的答案。

基本上,这是一个 maven pom,它是上述多模块项目中的一个子模块。我正在使用 dependency:unpack-dependencies,然后使用内联 groovy 脚本在每个 wsdl 文件上调用 deploy:deploy-file。这有点像 hackjob,但如果不对模块中 wsdl 文件的路径进行硬编码并在其上调用 deploy:deploy-file mojo 的多次执行,我想不出更好的方法来执行此操作,从而导致非常冗长pom.

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>rice</artifactId>
        <groupId>org.kuali.rice</groupId>
        <version>2.0.0-m7-SNAPSHOT</version>
    </parent>
    <artifactId>rice-dist-wsdl</artifactId>
    <name>Rice WSDL Distributions</name>
    <packaging>pom</packaging>

    <properties>
        <wsdl.location>${project.build.directory}/wsdl</wsdl.location>
    </properties>


    <!-- Depends on all API modules and modules that generate or contain wsdls -->
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-core-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-kew-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-kim-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-krms-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-ksb-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-shareddata-api</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-wsdls</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includes>**\/*.wsdl</includes>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                def repo_url
                                def repo_id
                                if ("${project.version}".endsWith("SNAPSHOT")) {
                                    repo_url = "${kuali.repository.snapshot.url}"
                                    repo_id = "${kuali.repository.snapshot.id}"
                                } else {
                                    repo_url = "${kuali.repository.release.url}"
                                    repo_id = "${kuali.repository.release.id}"
                                }

                                def wsdlGroupId = "${project.groupId}.wsdl"
                                new File("${wsdl.location}").eachFile() { file ->
                                    serviceName = file.name.split("\\.")[0]

                                    log.info("Deploying ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}")

                                    execString = "mvn deploy:deploy-file -Dfile=${file} -Durl=${repo_url} -DrepositoryId=${repo_id} "
                                    execString += "-DgroupId=${wsdlGroupId} -DartifactId=${serviceName} "
                                    execString += "-Dversion=${project.version} -Dpackaging=wsdl -Dclassifier=wsdl"

                                    def proc = execString.execute()
                                    proc.waitFor()

                                    err = proc.err.text
                                    if (err != null &amp;&amp; err.length() > 0) {
                                        log.error(err)
                                        fail("Deployment failed for ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}.  \n Run in verbose mode for full error.")
                                    } else {
                                        log.info("Successfully deployed ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}")
                                    }
                                }
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

最佳答案

另一种可能性:Maven Ant 任务可以 deploy files .我从未使用过它,但我敢打赌您可以使用 antrun 配置和一些 ant 模式匹配来获取和部署所有 WSDL。

关于java - Maven - 部署 :deploy-file over series of files within ${project. build.directory} (target/),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6713639/

相关文章:

java - Maven构建错误: Failed to execute goal org. apache.maven.plugins :maven-compiler-plugin:3. 5.1:编译

javascript - “meteor run android-device”需要永远安装 Cordova 插件

java - Tomcat - 当应用程序未正确部署时如何获取 http 500 而不是 404?

java - 如何将用户定义的数据类型中的值插入到java中的对象中?

java - Spring IoC - 依赖注入(inject) -> NullPointerException

java - 为什么 repaint() 在我的 JPanel 上不起作用?

java - 在集成测试之前使用 Maven 运行 Jetty

java - 创建 uber-jar 遇到困难

docker - 命中端点时如何在所有副本中更新

java - 将元素移动到第一位时,ArrayList 与 LinkedList 的复杂性