7

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

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

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

我不知道该怎么做是遍历每个文件并在每个 wsdl 上调用deploy:deploy-file 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,它是上述多模块项目中的一个子模块。我正在使用依赖项:解包依赖项,然后使用内联 groovy 脚本在每个 wsdl 文件上调用 deploy:deploy-file。这有点像 hackjob,但是如果不对模块中的 wsdl 文件的路径进行硬编码并在它们上调用 deploy:deploy-file mojo 的多次执行,我想不出更好的方法来做到这一点,导致非常冗长庞。

<?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>
4

2 回答 2

2

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

于 2011-07-16T03:44:16.040 回答
2

Build Helper 插件可能会帮助您。您可以让它发布 WSDL,但您必须明确列出每一个,并且它们的名称中都会包含您的 pom 的 artifactId。只有分类器可以改变。例如:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>attach-WSDLs</id>
            <phase>package</phase>
            <goals>
                <goal>attach-artifact</goal>
            </goals>
            <configuration>
                <artifacts>
                    <artifact>
                        <file>${project.build.directory}/foo.wsdl</file>
                        <classifier>foo</classifier>
                        <type>wsdl</type>
                    </artifact>
                    <artifact>
                        <file>${project.build.directory}/bar.wsdl</file>
                        <classifier>bar</classifier>
                        <type>wsdl</type>
                    </artifact>
                </artifacts>
            </configuration>
        </execution>
    </executions>
</plugin>

如果您的 pom 的坐标是 myGroupId:myArtifactId:1.1.1,那么使用此配置安装和部署的工件将被命名为 myArtifactId-1.1.1-foo.wsdl 和 myArtifactId-1.1.1-bar.wsdl。这是我所知道的最好的。

于 2011-07-16T02:33:35.687 回答