Maven - 部署:在 ${project.build.directory} (target/) 中的一系列文件上部署文件

发布于 2024-11-24 05:09:59 字数 11059 浏览 1 评论 0原文

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

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

  • 临时服务存储库(例如所述 此处
  • 为客户提供了一种简单的方法来使用cxf codegen 插件 通过指向 Maven 坐标 到目前为止,我得到的

是一个 pom 文件,它使用 dependency:unpack-dependency 将项目中的所有 wsdl 文件获取到一个目录中这个模块 ${project.build.directory} (通常被大家称为 target/ )。

我不知道该怎么做是循环遍历每个文件并调用 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>

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

[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-file。这有点像黑客工作,但我想不出更好的方法来做到这一点,而不需要硬编码模块中 wsdl 文件的路径并在它们上调用部署的多次执行: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>

Quick briefing on my situation - I'm working on a code base that has JAX-WS annotated interfaces/classes that we generate code-first wsdls from. We are using CXF's cxf-java2ws-plugin to generate wsdls at build time within maven for inclusion within the .jar produced for each module.

What we'd like to do is deploy these wsdl files to a maven repository since the maven repository can act as

  • a makeshift service repository (such as described here)
  • give clients an easy way to use the cxf codegen plugin by pointing to the maven coordinates for a wsdl instead of managing the wsdl files themselves

What I've got so far is a pom file that uses dependency:unpack-dependencies to get all of the wsdl files in the project in to one directory within this modules ${project.build.directory} (commonly known as target/ to everyone out there).

What I don't know how to do is to loop through each of these files and invoke deploy:deploy-file mojo on each wsdl. What are my options here since I really want to automate the process of deploying these wsdl files and not have anyone ever deploy them manually?

For completeness sake, here is the pom file:

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

Which shoves the wsdls in target/wsdl (they are contained within wsdl/ inside each .jar being depended upon):

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

Solution

Thought what I implemented was different than the accepted answer provided by Ryan Steward, I accepted his answer since it led me to write my own.

Basically, here is a maven pom that's a submodule in the multi-module project described above. I'm using dependency:unpack-dependencies and then using an in-line groovy script to call deploy:deploy-file on each of those wsdl files. It's a bit of a hackjob, but I couldn't think of a better way to do this without hardcoding paths to the wsdl files in the module and calling several executions of the deploy:deploy-file mojo on them, leading to a very verbose 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 && 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>

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

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

发布评论

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

评论(2

谜泪 2024-12-01 05:09:59

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

Another possibility: the Maven Ant tasks can deploy files. I've never used it, but I'll bet you could use an antrun configuration and some ant pattern matching to pick up and deploy all the WSDLs.

溺孤伤于心 2024-12-01 05:09:59

构建助手插件可能会帮助你。您可以让它发布 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。这是我所知道的最好的。

The Build Helper plugin might help you out. You can make it publish the WSDLs, but you'll have to list each one out explicitly, and they'll all have the artifactId of your pom in their names. Only the classifier can change. For example:

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

If your pom's coordinate is myGroupId:myArtifactId:1.1.1, then the artifacts installed and deployed using this config would be named myArtifactId-1.1.1-foo.wsdl and myArtifactId-1.1.1-bar.wsdl. That's the best I know of.

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