gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:23:00 25 4
gpt4 key购买 nike

简要介绍一下我的情况 - 我正在处理一个代码库,该代码库具有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com