Java Maven-deploy:在${project.build.directory}(target/)中的一系列文件上部署文件
简要介绍一下我的情况——我正在开发一个代码库,该代码库中有JAX-WS注释的接口/类,我们首先从这些接口/类生成代码WSDL。我们使用CXF的CXF-java2ws-plugin在maven内部构建时生成wsdl,以包含在为每个模块生成的.jar中 我们要做的是将这些wsdl文件部署到maven存储库中,因为maven存储库可以充当Java Maven-deploy:在${project.build.directory}(target/)中的一系列文件上部署文件,java,maven,deployment,wsdl,kuali,Java,Maven,Deployment,Wsdl,Kuali,简要介绍一下我的情况——我正在开发一个代码库,该代码库中有JAX-WS注释的接口/类,我们首先从这些接口/类生成代码WSDL。我们使用CXF的CXF-java2ws-plugin在maven内部构建时生成wsdl,以包含在为每个模块生成的.jar中 我们要做的是将这些wsdl文件部署到maven存储库中,因为maven存储库可以充当 临时服务存储库(如所述) 通过指向wsdl的maven坐标,而不是管理wsdl文件本身,为客户机提供一种简单的方法来使用 到目前为止,我得到的是一个pom文件,
- 临时服务存储库(如所述)
- 通过指向wsdl的maven坐标,而不是管理wsdl文件本身,为客户机提供一种简单的方法来使用
<?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>
解决方案 虽然我实现的与Ryan Steward提供的公认答案不同,但我接受了他的答案,因为这让我写下了自己的答案 基本上,这里是一个maven pom,它是上述多模块项目中的一个子模块。我使用dependency:unpack dependencies,然后使用一个内嵌的groovy脚本在每个wsdl文件上调用deploy:deploy文件。这有点麻烦,但是如果不在模块中对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 && 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.0.0
大米
org.kuali.rice
2.0.0-m7-快照
大米区
大米分配
聚甲醛
${project.build.directory}/wsdl
${project.groupId}
米芯原料药
${project.version}
${project.groupId}
米丘原料药
${project.version}
${project.groupId}
米金api
${project.version}
${project.groupId}
大米原料药
${project.version}
${project.groupId}
大米原料药
${project.version}
${project.groupId}
大米沙利达api
${project.version}
org.apache.maven.plugins
maven依赖插件
解包wsdl
产生资源
解包依赖项
**\/*.wsdl
${project.build.directory}
org.codehaus.gmaven
gmaven插件
部署
执行
def repo_url
def回购id
如果(“${project.version}”.endsWith(“快照”)){
repo_url=“${kuali.repository.snapshot.url}”
repo_id=“${kuali.repository.snapshot.id}”
}否则{
repo_url=“${kuali.repository.release.url}”
repo_id=“${kuali.repository.release.id}”
}
def wsdlGroupId=“${project.groupId}.wsdl”
新文件(“${wsdl.location}”).eachFile(){File->
serviceName=file.name.split(“\\”)[0]
log.info(“将${wsdlGroupId}:${serviceName}:wsdl:${project.version}部署到${repo_id}”)
execString=“mvn deploy:deploy file-Dfile=${file}-Durl=${repo\u url}-DrepositoryId=${repo\u id}”
execString+=“-DgroupId=${wsdlGroupId}-DartifactId=${serviceName}”
execString+=“-Dversion=${project.version}-Dpackaging=wsdl-Dclassifier=wsdl”
def proc=execString.execute()
waitFor()程序
err=proc.err.text
if(err!=null&;err.length()>0){
日志错误(err)
失败(“将${wsdlGroupId}:${serviceName}:wsdl:${project.version}部署到${repo_id}失败。\n在详细模式下运行以获取完整错误。”)
}否则{
log.info(“成功地将${wsdlGroupId}:${serviceName}:wsdl:${project.version}部署到${repo_id}”)
}
}
构建助手插件可能会帮助您。您可以让它发布wsdl,但是您必须明确列出每个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>
或
<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>