Code coverage of JBoss AS 7 testsuite, using JaCoCo - no data in jacoco.exec files - jboss

I'm trying to get coverage of JBoss AS 7. Here's my branch:
https://github.com/OndraZizka/jboss-as/tree/TS-jacoco
When I run mvn clean install -rf testsuite -DallTests -Dcoverage -fae I get (almost) empty jacoco.exec files - just some metadata (size is few bytes).
The JVM arg line used is:
-javaagent:${jbossas.ts.dir}/target/jacoco-jars/agent/jacocoagent.jar=destfile=${basedir}/target/jacoco.exec,includes=${jboss.home}/modules/**/*,excludes=${basedir}/target/classes/**/*,append=true,output=file
This line is passed to Arquillian to use to start JBoss AS 7.
The testsuite runs, the argument is passed (it appears in AS7's boot.log), but the resulting jacoco.exec file is only few bytes in size. The report of course shows no coverage.
What am I doing wrong?

Resolved - the "includes" and "excludes" parameters of the agent refer to class names, not files.
Correct JVM agent argument for my case is:
-javaagent:${jbossas.ts.dir}/target/jacoco-jars/agent/jacocoagent.jar=destfile=${basedir}/target/jacoco.exec,includes=*,excludes=org.jboss.as.test.*,append=true,output=file
My aproach was to configure the maven jacoco plugin to get the argument, and then hard-coded the property into pom.xml since the property generated by the plugin is not passed to the Surefire plugin.
<profile>
<id>ts.jacoco.profile</id>
<activation><property><name>coverage</name></property></activation>
<properties>
<jvm.args.jacoco>-javaagent:${jbossas.ts.dir}/target/jacoco-jars/agent/jacocoagent.jar=destfile=${basedir}/target/jacoco.exec,includes=*,excludes=org.jboss.as.test.*,append=true,output=file</jvm.args.jacoco>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.jacoco.plugin}</version>
<executions>
<execution><id>ts.jacoco-prepare</id>
<phase>process-test-classes</phase>
<goals><goal>prepare-agent</goal></goals>
<configuration>
<append>true</append>
<destFile>target/jacoco.exec</destFile>
<includes>
<include>*</include>
</includes>
<excludes>
<exclude>org.jboss.as.test.*</exclude>
</excludes>
<output>file</output>
<propertyName>jvm.args.jacoco</propertyName>
</configuration>
</execution>
<!-- Doesn't work currently - waiting for JaCoCo to fix this. Moved to the Ant plugin execution. -->
<execution><id>ts.jacoco.report</id>
<phase>none</phase> <!-- post-integration-test -->
<goals><goal>report</goal></goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
<outputDirectory>target/coverageReport</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Copy JaCoCo jars to have them for the Ant plugin. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<!-- Copy the ant tasks jar. Needed for ts.jacoco.report-ant . -->
<execution> <id>ts.jacoco.dep.ant</id> <goals><goal>copy</goal></goals> <phase>process-test-resources</phase> <inherited>false</inherited>
<configuration>
<artifactItems>
<artifactItem><groupId>org.jacoco</groupId><artifactId>org.jacoco.ant</artifactId><version>${version.jacoco.plugin}</version></artifactItem>
</artifactItems>
<stripVersion>true</stripVersion>
<outputDirectory>${basedir}/target/jacoco-jars</outputDirectory>
</configuration>
</execution>
<!-- Copy the agent jar. Needed for ${jvm.args.jacoco} to have this jar on known path.
If the ts.jacoco-prepare worked and really put the value into the property, this might go away. -->
<execution> <id>ts.jacoco.dep.agent</id> <goals><goal>unpack</goal></goals> <phase>process-test-resources</phase> <inherited>false</inherited>
<configuration>
<artifactItems>
<artifactItem><groupId>org.jacoco</groupId><artifactId>org.jacoco.agent</artifactId><version>${version.jacoco.plugin}</version></artifactItem>
</artifactItems>
<stripVersion>true</stripVersion>
<outputDirectory>${basedir}/target/jacoco-jars/agent</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Ant plugin. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<!-- DEBUG -->
<execution>
<id>ts.jacoco.debug</id>
<phase>post-integration-test</phase>
<goals><goal>run</goal></goals>
<inherited>false</inherited>
<configuration>
<target>
<echo>Jacoco argline: ${jvm.args.jacoco}</echo>
<echo>Jacoco jar: ${basedir}/target/jacoco-jars/org.jacoco.ant.jar</echo>
</target>
</configuration>
</execution>
<!-- Must be run using Ant due to https://sourceforge.net/tracker/?func=detail&aid=3474708&group_id=177969&atid=883354 -->
<execution>
<id>ts.jacoco.report-ant</id>
<phase>site</phase> <!-- post-integration-test -->
<goals><goal>run</goal></goals>
<inherited>false</inherited>
<configuration>
<target>
<taskdef name="report" classname="org.jacoco.ant.ReportTask">
<classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar"/>
</taskdef>
<echo>Creating JaCoCo test coverage reports...</echo>
<mkdir dir="${basedir}/target/coverage-report"/>
<report>
<executiondata>
<fileset dir="${basedir}">
<include name="**/target/jacoco.exec"/>
</fileset>
</executiondata>
<structure name="AS 7 project">
<classfiles>
<fileset dir="${jboss.dist}/modules">
<include name="**/*.jar"/>
<!-- We have 2.x in main. -->
<exclude name="com/sun/jsf-impl/1.*/**/*"/>
<!-- AS7-3383 - com/sun/codemodel vs. /1.0/com/sun/codemodel -->
<exclude name="com/sun/xml/**/*"/>
<exclude name="javax/faces/api/1.2/**/*"/>
<!-- AS7-3390 -->
<exclude name="org/apache/commons/beanutils/**/*"/>
<!-- AS7-3389 -->
<exclude name="org/python/jython/standalone/**/*"/>
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${jbossas.project.dir}">
<include name="**/*.java"/>
<exclude name="testsuite/**/*.java"/>
</fileset>
</sourcefiles>
</structure>
<html destdir ="${basedir}/target/coverage-report/html"/>
<xml destfile="${basedir}/target/coverage-report/coverage-report.xml"/>
<csv destfile="${basedir}/target/coverage-report/coverage-report.csv"/>
</report>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${version.jacoco.plugin}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>

Related

Multi module Scala project gives 0% sonar code coverage

I am using SonarQube Enterprise EditionVersion 7.9.1. I am running maven goal for my multi-module scala project as :
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar
After successfull completion, I am getting 0% code coverage. Below is my sonar.properties:
sonar.junit.reportsPath=target/surefire-reports
sonar.surefire.reportsPath=target/surefire-reports
sonar.jacoco.reportPath=target/coverage-reports/jacoco-unit.exec
sonar.binaries=target/classes
sonar.java.coveragePlugin=jacoco
sonar.verbose=true
Below is pom.xml
<modules>
<module>1</module>
<module>2/module>
<module>3</module>
<module>4</module>
</modules>
<properties>
<!-- Sonar -->
<sonar.version>3.7.0.1746</sonar.version>
<jacoco.version>0.7.9</jacoco.version>
<sonar.projectName>ds</sonar.projectName>
<sonar.projectDescription>**</sonar.projectDescription>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.reportPaths>${project.build.directory}/jacoco.exec</sonar.jacoco.reportPaths>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.language>scala</sonar.language>
<sonar.sources>src/main</sonar.sources>
<!--<sonar.tests>src/test</sonar.tests> -->
<scoverage.plugin.version>1.4.1</scoverage.plugin.version>
<sonar.scala.scoverage.reportPath>target/scoverage.xml</sonar.scala.scoverage.reportPath>
<junit.version>4.11</junit.version>
<!-- Sonar -->
</properties>
<profiles>
<!-- Sonar -->
<profile>
<id>coverage-per-test</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- Sonar -->
</profiles>
</project>
I am getting the coverage as 0%, when there are many unit test written. How should I fix this?

Execute a task in Maven before packaging

I don't understand how to run a task in Maven, before packaging.
<build>
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<tasks>
<echo message="****** TEST *****" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
When I run mvn clean package, it doesn't get executed. How can I have this task executed? I'm using maven 3.0.5, if it matters.
** UPDATE: **
Adding id and goal as suggested, solved the problem from the command line.
<id>my-generate-sources</id>
<goals>
<goal>run</goal>
</goals>
To fix Eclipse error, I've configured lifecyleMappingMetadata, within the build section:
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<versionRange>[1.7,)</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
You need to add the <goals> tag (and adding an <id> tag is also strongly encouraged though not required if you only have one <execution> for the plugin), e.g.
...
<execution>
<id>print-something</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo message="****** TEST *****" />
</tasks>
</configuration>
</execution>
...
Try adding an execution id:
<execution>
<phase>generate-sources</phase>
<id>my-generate-sources</id>
<configuration>
<tasks>
<echo message="****** TEST *****" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
UPDATE
I forgot the run goal, as Guillame said. Eclipse maven integration is one of the worse things I have ever seen. The way we were running it is exclusivley via maven command line, and that is what I would recommend. You can still run it from eclipse like this:
create a new empty project
create mvn-clean-package.launch file in it
The file should look like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${resource}"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.ui.externaltools.launchGroup"/>
</listAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="/usr/bin/mvn"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="clean package -DskipTests=true -U"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${selected_resource_loc}"/>
</launchConfiguration>
As long as this project is opened in your workspace, you can select any other project folder that contains pom.xml and select your mvn-clean-package command from the external tools button:
This will run:
mvn clean package -DskipTests=true -U
from the selected folder. You can see the output in Eclipse console window.
The external tools are also accessible also from the Run menu. I suppose that there is method to achieve this through Eclipse UI, but I didn't use Eclipse long enough to find that out.

Run maven gwt application in hosted mode

I have created gwt maven project and I want run it so from command line I am providing:
mvn compile gwt:run -DrunTarget=com.engile.Engile/Engile.html
But In logs it shows:
ava.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1847)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at com.appops.server.data.hibernate.SessionProvider.createSessionFactory(SessionProvider.java:46)
at com.appops.server.data.hibernate.HibernateDataSourceConnector.init(HibernateDataSourceConnector.java:39)
at com.engile.server.services.ConfigurationServlet.init(ConfigurationServlet.java:45)
at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:117)
at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:102)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4363)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
and pom.xml includes:
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.4.0</gwtVersion>
<!-- GWT needs at least java 1.5 -->
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<!-- <versionRange>[2.5.0,)</versionRange> -->
<version>${gwtVersion}</version>
<goals>
<goal>resources</goal>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
<configuration>
<runTarget>Engile.html</runTarget>
<hostedWebapp>${project.build.directory}/${project.build.finalName} </hostedWebapp>
<modules>
<module>com.engile.Engile</module>
</modules>
<!-- <runTarget>com.engile.Engile/Engile.html</runTarget> -->
</configuration>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<versionRange>[2.1.1,)</versionRange>
<goals>
<goal>exploded</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
In build path in source section I am providing outputfolder of src/main/java is target/classes and default output folder is:
engilev2_with_mavenold/src/main/webapp/WEB-INF/classes
is anything is wrong, I don't understand the webapp/classes folder and target/classes folder where java classes are compiled to ?
You have not configured gwt-maven-plugin in your build tag. You are only configuring maven-compiler-plugin and lifecycle-mapping plugin. The gwt-maven-plugin under lifecycle-plugin is only to inform eclipse to avoid invoking gwt compilation in refresh cycles,
You have the same issue in the other stackoverflow question too -
The parameters 'runTarget' for goal org.codehaus.mojo:gwt-maven-plugin:2.5.0:run are missing or invalid
Add another plugin tag in your pom.xml under buil tag after maven-compiler-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<!-- <versionRange>[2.5.0,)</versionRange> -->
<version>${gwtVersion}</version>
<goals>
<goal>resources</goal>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
<configuration>
<runTarget>Engile.html</runTarget>
<hostedWebapp>${project.build.directory}/${project.build.finalName} </hostedWebapp>
<modules>
<module>com.engile.Engile</module>
</modules>
<!-- <runTarget>com.engile.Engile/Engile.html</runTarget> -->
</configuration>
</plugin>

Using Maven for deployment

I have this task for the project with 4 nested subprojects using Maven:
For each child: jar-up resource directory including project dependencies
Move up to the parent project
With a single command extract all created archives into various remote destinations (full install), that may include http server, app server, file server, etc. (mostly *NIX). Destination is provided on subproject level
It should also be possible to unzip/copy from the individual subproject (partial install)
Files are not Java - mostly various scripts and HTML
I'm looking at the various plugins to help with the task: assembly, dependency, antrun, unzip. Dependency looks promising but I need to unzip not only dependency jars but the (sub)project content as well. Also since I can't really tight the operation to the Maven lifecycle how would I trigger remote install? mvn dependency:unpack? That's not very descriptive or intuitive. Is is possible to create a custom goal (e.g. project:install) without writing a plugin?
Using Maven is company standard so please do not offer alternatives - I'm pretty much stuck with what I have
Ok, I think the following might do what you need. The drawback of this approach is that there will be an interval between each deployment as the subsequent build is executed. Is this acceptable?
Define a profile in each project with the same name (say "publish"). Within that profile you can define a configuration to use the antrun-plugin to deliver the files with FTP (see below).
In the parent project you'll have a modules element, defining each project as a module. If you run mvn install -P publish, each project will be built in turn with the publish profile enabled, and the final artifact published to the target during the install phase. If you need to deploy additional files, modify the include element accordingly.
Note the parameters for the FTP task have been set as properties, this allows them to be overridden from the command-line and/or inherited 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 could use the dependency plugin to download each dependency, except that a parent can't have a dependency on a child, and it will be built before the child. It would have to be another project. you also need to have somewhere the information for where to deploy them to. At the moment you have the target information in the individual projects so it isn't accessible in the deployer project.
Taking this approach, you can define multiple profiles in the new project, one for each artifact. Each profile defines a dependency:copy execution to obtain the jar and an antrun execution for one of the projects. Common configuration (such as the dependencies for the antrun plugin) can be pulled out of the profiles. Also be aware that the properties will be merged if you define multiple profiles, so yo may need to qualify them with the 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>
Below POM will help to copy jar's file from project build directory to remote SFTP/FTP server.
Use command mvn install -Dftp.password=password
Since I want to pass password from command prompt for security reason, I have used -Dftp.password=password
After execution of above command all the jar files from maven project target folder will be deployed in 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>
Does not work without 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 favourite is
<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>
though I don't know how compatible that is over different platforms.
I would look at using the maven-assembly-plugin to do this.
Something like this can be used to grab the files from the child projects and stuff them in 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>
Maven is not really designed to deploy jars to a remote location; its main use is compiling and packaging artifacts. The assembly and dependency targets are primarily used to gather dependencies and files to package into an artifact.
Having said that, maven does have a deploy goal which uses a component called wagon. This is primarily intended to deploy to a maven repository. There is a plugin called Cargo that can be used to deploy artifacts to a remote server, but that doesn't explode the jar contents by itself (it relies on the target app server to do all that). You might be able to extend the Maven Wagon functionality yourself.
Also, it is possible to package a custom lifecycle, but that is getting into some pretty low level maven mojo (pun intended).

maven-war-plugin vs. "Unexpected end of ZLIB input stream"

im using maven-war-plugin and sometimes i get Unexpected end of ZLIB input stream when deploying to jboss, its because file is made in jboss directory and not moved/copied there, is there any way to fix it(using maven)?
my configuration:
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputDirectory>${jbossDeploy}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
Most likely what you have said is correct.
Maven is probably still building the war when jboss starts to deploy it, so as jboss is reading it, it sees an invalid zip format. You could try using the exploded option, or deploy separately after everything is built.
I made ant script for it that can be used in maven
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<property name="packageName" value="${project.build.finalName}.${project.packaging}" />
<property name="outputDir" value="c:/jboss-4.2.1.GA/server/default/deploy" />
<property name="file" value="${project.build.directory}\${packageName}" />
<property name="tofile" value="${outputDir}/${packageName}" />
<echo message="Moving ${file} to ${tofile}" />
<move file="${file}" tofile="${tofile}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>