Using Maven for Deployment

I have this task for a project with 4 nested subprojects using Maven:

  • For each child resource: jar-up resource directory, including project dependencies
  • Go to parent project
  • Using one command, extract all created archives to various remote destinations (full installation), which may include an http server, application server, file server, etc. (mostly * NIX). Assignment is provided at subproject level
  • It should also be possible to unpack / copy from a separate subproject (partial installation)

Non Java Files - Mostly Various Scripts and HTML

I consider various plugins to help with the task: assembly, dependency, antrun, unzip. The dependency looks promising, but I need to unzip not only the dependency banks, but also the content of the (sub) project. Also, since I cannot severely limit the Maven life cycle, how would I start a remote installation? mvn addiction: unzip? It is not very descriptive or intuitive. Is it possible to create a custom goal (for example, a project: install) without writing a plugin?

Using Maven is the company's standard, so please do not offer an alternative - I am pretty much fixated on what I have

+19
maven-2 deployment
Sep 10 '09 at 15:23
source share
5 answers

Well, I think the following can do what you need. The disadvantage of this approach is that there will be a gap between each deployment, as subsequent assembly is performed. It is acceptable?

Define a profile in each project with the same name (say, "publish"). Inside this profile, you can define the configuration for using the antrun-plugin to deliver files from FTP (see below).

In the parent project, you will have a module element that defines each project as a module. If you run mvn install -P publish , each project will be built in turn with the publishing profile turned on, and the final artifact will be published to the landing page at the installation stage. If you need to deploy additional files, modify the include element accordingly.

Please note that the parameters for the FTP task are set as properties, this allows you to override them from the command line and / or inherit from the parent 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> 



Update: based on your comment: you can use the dependency plugin to load each dependency, except that the parent cannot have a dependency on the child, and it will be created before the child. It was supposed to be another project. You also need to have information on where to deploy them. At the moment, you have targeted information in individual projects, so it is not available in the deployment project.

Using this approach, you can define several profiles in a new project, one for each artifact. Each profile defines a dependency: performing a copy to get a jar and performing antrun for one of the projects. The usual configuration (such as dependencies for the antrun plugin) can be pulled out of profiles. Also keep in mind that the properties will be merged if you define multiple profiles, so you may need to qualify them with an artifact name, for example 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> 
+12
Sep 10 '09 at 16:41
source share

Below POM will help to copy the jar file from the project build directory to the remote SFTP / FTP server.

  • Use the mvn install -Dftp.password = password command

Since I want to transfer the password from the command line for security reasons, I used -Dftp.password = password After executing the above command, all jar files from the target folder of the maven project will be deployed to the MAVEN folder on server.com

  <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> 
+5
Jun 26 '15 at
source share

Doesn't work without a passphrase.

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

However my favorite

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

although I don’t know how compatible it is on different platforms.

+1
Jul 01 '14 at 12:08
source share

I would look at using maven-assembly-plugin for this.

Something like this can be used to capture files from child projects and populate them in the output directories.

 <assembly> <id>xyzzy</id> <formats> <format>zip</format> </formats> <fileSets> <fileSet> <directory>../subproject1/target/</directory> <outputDirectory>/foo</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> <fileSet> <directory>../subproject1/target/html-output/</directory> <outputDirectory>/foo</outputDirectory> <includes> <include>*.html</include> <include>*.js</include> <include>*.css</include> </includes> </fileSet> <fileSet> <directory>../subproject2/target/</directory> <outputDirectory>/bar</outputDirectory> <includes> <include>**/**</include> </includes> <excludes> <exclude>**/*.exclude-this</exclude> </excludes> </fileSet> </fileSets> </assembly> 
0
10 Sep '09 at 20:23
source share

Maven is not designed to deploy banners in a remote location; its main use is the collection and packaging of artifacts. Build goals and dependencies are mainly used to collect dependencies and files for packaging into an artifact.

Having said that, maven has a deployment target that uses a component called a wagon. This is primarily intended to be deployed to the maven repository. There is a plugin called Cargo, which can be used to deploy artifacts to a remote server, but by itself it does not explode the contents of the container (it relies on the server of the target application to do all this). You may be able to extend the functionality of the Maven Wagon yourself.

You can also pack the user life cycle, but it falls into the rather low-level maven mojo (pun intended).

0
Sep 10 '09 at 21:38
source share



All Articles