我使用Maven对包含4个嵌套子项目的项目执行以下任务:
jar-up资源目录包括项目dependencies
解压/复制
文件不是Java -主要是各种脚本和HTML
我正在寻找各种插件来帮助完成这项任务: assembly,dependency,antrun,unzip。依赖项看起来很有希望,但我不仅需要解压缩依赖项jars,还需要解压缩(子)项目内容。另外,由于我不能对Maven生命周期进行严格的操作,我如何触发远程安装呢?mvn依赖关系:解包?这不是很有描述性或直观性。是否可以在不编写插件的情况下创建自定义目标(例如project:install)?
使用Maven是公司的标准,所以请不要提供替代方案-我很难使用我已有的东西
发布于 2009-09-10 16:41:19
好的,我认为下面的代码可能会满足你的需求。这种方法的缺点是,在执行后续构建时,每次部署之间会有一段时间间隔。这可以接受吗?
在每个项目中定义一个具有相同名称的概要文件(比如"publish")。在该配置文件中,您可以定义一个配置,以使用antrun-plugin通过FTP传递文件(见下文)。
在父项目中,您将有一个modules元素,将每个项目定义为一个模块。如果您运行mvn install -P publish
,那么每个项目都将在启用发布概要文件的情况下依次构建,并在安装阶段将最终工件发布到目标。如果需要部署其他文件,请相应地修改include element
。
注意: FTP任务的参数已设置为属性,这允许从命令行覆盖它们和/或从父POM继承它们。
<profiles>
<profile>
<id>publish</id>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<tasks>
<ftp action="send"
server="${ftp.host}" remotedir="${ftp.remotedir}"
userid="${ftp.userid}" password="${ftp.password}"
depends="${ftp.depends}" verbose="${ftp.verbose}">
<fileset dir="${project.build.directory}">
<include
name="${project.build.finalName}.${project.packaging}"/>
</fileset>
</ftp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>
<properties>
<ftp.host>hostname</ftp.host>
<ftp.remotedir>/opt/path/to/install</ftp.remotedir>
<ftp.userid>user</ftp.userid>
<ftp.password>mypassword</ftp.password>
<ftp.depends>yes</ftp.depends>
<ftp.verbose>no</ftp.verbose>
</properties>
</profile>
</profiles>
更新:基于您的评论:您可以使用依赖项插件下载每个依赖项,但父项不能对子项具有依赖项,它将在子项之前构建。这必须是另一个项目。您还需要在某个地方保存部署它们的位置的信息。目前,您在各个项目中都有目标信息,因此无法在部署程序项目中访问这些信息。
采用这种方法,您可以在新项目中定义多个概要文件,每个工件一个。每个概要文件都定义了一个依赖项:复制执行以获取jar,并为其中一个项目定义了antrun执行。可以从概要文件中提取公共配置(例如antrun插件的依赖项)。还要注意,如果您定义了多个概要文件,则属性将被合并,因此您可能需要使用工件名称来限定它们,例如ftp.artifact1.host
。
<profiles>
<profile>
<id>deploy-artifact1</id>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependency</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>name.seller.rich</groupId>
<artifactId>artifact1</artifactId>
<version>1.0.0</version>
<type>jar</type>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/deploy-staging</outputDirectory>
<overWriteReleases>false</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<tasks>
<ftp action="send"
server="${ftp.host}" remotedir="${ftp.remotedir}"
userid="${ftp.userid}" password="${ftp.password}"
depends="${ftp.depends}" verbose="${ftp.verbose}">
<fileset dir="${project.build.directory} includes="deploy-staging/"/>
</ftp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<properties>
<!--if the properties differ between targets, qualify them with the artifact name-->
<ftp.host>hostname</ftp.host>
<ftp.remotedir>/opt/path/to/install</ftp.remotedir>
<ftp.userid>user</ftp.userid>
<ftp.password>mypassword</ftp.password>
<ftp.depends>yes</ftp.depends>
<ftp.verbose>no</ftp.verbose>
</properties>
</profile>
</profiles>
发布于 2015-06-27 03:13:07
下面的POM将有助于将jar文件从项目构建目录复制到远程SFTP/FTP服务器。
由于出于安全原因,我想从命令提示符传递密码,所以在执行上述命令后,我使用了-Dftp.password=password,所有来自maven项目目标文件夹的jar文件都将部署到server.com上的MAVEN文件夹中
<plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<tasks>
<scp todir="user@server.com:/MAVEN/"
sftp="true" port="22" trust="true" password="${ftp.password}"
failonerror="false" verbose="true" passphrase="">
<fileset dir="${project.build.directory}">
<include name="*.jar" />
</fileset>
</scp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
</plugin>
发布于 2014-07-01 20:08:51
如果没有口令,则无法工作。
<profile>
<id>publish</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>scp</id>
<phase>deploy</phase>
<configuration>
<tasks>
<scp todir="user@host:some/remote/dir"
sftp="true"
keyfile="${user.home}/.ssh/devel-deploy.id_dsa"
failonerror="false"
verbose="true"
passphrase="nopass"
>
<fileset dir="${project.build.directory}">
<include
name="${project.build.finalName}.${project.packaging}"/>
</fileset>
</scp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
然而,我最喜欢的是
<profile>
<id>upload-devel</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>upload-devel</id>
<phase>deploy</phase>
<configuration>
<target>
<exec executable="rsync" failonerror="false">
<arg value="-aiz" />
<arg value="${project.build.directory}/${project.artifactId}.${project.packaging}" />
<arg value="user@host:some/remote/dir/." />
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
虽然我不知道它在不同平台上的兼容性如何。
https://stackoverflow.com/questions/1405979
复制相似问题