In an answer here it is suggested to create a bat file to convert JTL file into CSV file which will have "save table data."
Jmeter command line to "save table data" in a aggregate report
I have added CMDRunner.jar maven dependency in project's pom.xml file. Using this I want to write a piece of java code that would help me to do what bat file is doing above.
I don't understand the functions given in this api/jar. How do I start?
Later I would have maven life cycle which would run as follows:
mvn clean verify > Output will be jtl file
mvn test > JTL converted to CSV using piece of code from above
mvn sendreports > send csv to email
If you don't know how to use JMeter Plugins API the easiest way would be going for Maven Exec plugin, this way you will be able to execute JMeterPluginsCMD Command Line Tool with necessary parameters in arbitrary phase of Maven Build Lifecycle
Example pom.xml file would look like:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jmeter-maven</groupId>
<artifactId>com.example.jmeter-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.7.0</version>
<configuration>
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins-cmd:2.1</artifact>
<artifact>kg.apc:cmdrunner:2.2.1</artifact>
<artifact>kg.apc:jmeter-plugins-cmn-jmeter:0.6</artifact>
<artifact>kg.apc:jmeter-plugins-graphs-basic:2.0</artifact>
<artifact>kg.apc:jmeter-plugins-synthesis:2.1</artifact>
<artifact>kg.apc:jmeter-plugins-filterresults:2.1</artifact>
</jmeterExtensions>
<downloadExtensionDependencies>false</downloadExtensionDependencies>
</configuration>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<execution>
<id>jmeter-check-results</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>copy-cmdrunner-to-lib-folder</id>
<phase>post-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<basedir>${basedir}/target/jmeter/lib/ext</basedir>
<executable>cp</executable>
<commandlineArgs>cmdrunner-2.2.1.jar ..</commandlineArgs>
</configuration>
</execution>
<execution>
<id>generate-aggregate-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<basedir>${basedir}/target/jmeter/lib</basedir>
<executable>java</executable>
<commandlineArgs>-jar cmdrunner-2.2.1.jar --tool Reporter --generate-csv ${basedir}/target/aggregate.csv --input-jtl ${basedir}/target/jmeter/results/${timestamp}-test.csv --plugin-type AggregateReport</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
It will produce aggregate.csv file in target folder which will contain textual representation of the Aggregate Report data
For non-Maven executions you can install the required plugins using JMeter Plugins Manager
Related
I'm using the maven-deploy-plugin to deploy a third party jar (previously downloaded to my target directory from a plugin not show here) to Nexus as the name 'third-party-1.0.jar', this all works fine using the configuration below.
I also have a javadoc directory in my target directory, which is the javadoc for this third party jar. I'd like to package that javadoc directory as 'third-party-1.0-javadoc.jar'.
If I could get the directory packaged as a JAR, I think I could the javadoc parameter of the deploy plugin below to deploy it, just unsure how to package a custom directory as a JAR with a specific name using Maven, maybe the assembly plugin?
TLDR; How do I use Maven to create a JAR file from the contents of a directory I specify?
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<id>deploy-jar</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/code.jar</file>
<url>...</url>
<repositoryId>...</repositoryId>
<url>...</url>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<groupId>com.example</groupId>
<artifactId>third-party</artifactId>
<version>1.0</version>
</configuration>
</execution>
</executions>
</plugin>
You can achieve it by using maven-jar-plugin or by using maven-assembly-plugin
Here is a way to achieve it via maven-jar-plugin
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<configuration>
<classifier>docs</classifier>
<classesDirectory>${project.build.directory}/docs</classesDirectory>
<includes>**/*</includes>
</configuration>
<id>pack-docs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
Now run:
mvn clean package
It will create artifact_name-1.0.0-docs.jar jar
How to create addition jar using Maven?
I ended up using the maven-assembly-plugin instead of the maven-jar-plugin as it allows more control over the resulting JAR, including not adding a pom.xml to it, not attaching it to the project as an artifact to be deployed (attach=false), and how it
is named. This allows the maven-deploy-plugin to control how it is deployed, and what Maven coordinates to use when deploying it.
I can then just attach the Javadoc JAR built with the assembly plugin into my deploy file execution using the javadoc tag:
src/main/assembly/assembly.xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>package-third-party-javadoc</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/dir</directory>
<outputDirectory>.</outputDirectory>
</fileSet>
</fileSets>
</assembly>
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>package-third-party-javadoc</id>
<phase>compile</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<finalName>third-party-javadoc</finalName>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<id>deploy-jar</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/code.jar</file>
<url>...</url>
<repositoryId>...</repositoryId>
<url>...</url>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<groupId>com.example</groupId>
<artifactId>third-party</artifactId>
<version>1.0</version>
<javadoc>${project.build.directory}/third-party-javadoc.jar</javadoc>
</configuration>
</execution>
</executions>
</plugin>
I'm having really weird issue - I have created multi-module java project that creates "fat-jar". Unfortunetly the "frontend" module jar doesn't have resources in it when launched on jenkins(linux) - it does work on Windows for some reason:
This is the "frontend" pom:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.frontend</groupId>
<artifactId>frontend-app</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>dist</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>node build app</id>
<phase>prepare-package</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run-script build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I have tried with:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
But that did not help neither.
The default npm build goal is
ng build --output-path dist/META-INF/resources
Jar file in target does not include files from "dist" -> it also does not work when I create it in default location src/main/resources
The maven log output includes this:
[WARNING] JAR will be empty - no content was marked for inclusion!
The dist directory is created and filled during build. Maven locates files on Windows but does not on Jenkins.
EDIT:
The maven goals are the same.
You could check few things on Jenkins. First if mvn goal is exactly same. Second, whether all resources are checked out properly or not. Also, see if file write permission are there for the linux user used by Jenkins process. Finally, append a -X behind your goals on Jenkins to see maven logs in detail and debug your issue.
Googled this question but no straight answer was found sadly.
So, I have a Maven project. I want to upload my release to Maven Central Repository. This means I need to create 3-4 jar files:
Compiled source jar
Javadoc jar
Source code jar
Tests jar (optional)
How can I create all these jars? Add some configuration to POM?
BTW, I am using latest Netbeans IDE, but this shouldn't matter :)
Any help is appreciated!
EDIT
So this is my POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>sdk</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5.3</version>
<executions>
<execution>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Maven can create these jars for your. Next to 1,2,3,4 you will also need to sign your release artifacts. To get the artifact into maven central I would advise you to read:
The official Maven guide to get your artifact into maven central
The guide from the Open Source Sonatype repository. It contains all the information you will need to know.
With regards to your pom.xml you can add a separate release profile, which builds all these artifacts for you.
Just add the following profile to your pom.xml
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Now when you want to create the release you can just call:
mvn clean install -Prelease
and it will create all the required artifacts.
Take a look at this guide and this. You need to raise a ticket for a mirror repository of your choice, then you need to use additionally plugins for signing jar, generating documents, adding source and doing remote deployment for you.
I would like to execute git describe as part of a maven build and use the resulting output in the manifest for building a .jar package.
I know how to do this in ant via the <exec> task with outputproperty to an ant property variable, but I have very little experience with Maven and don't even know where to look.
Is this possible?
I found this in a sample pom.xml file so adding something to the manifest looks pretty easy:
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>my.class.here.Myclass</mainClass>
<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>lib/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension}</customClasspathLayout>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Not sure how to capture command execution though.
Here is a suggested approach:
Use the Exec Maven Plugin for launching your git commands and write to a properties file (name=value pattern, if possible)
Use the Properties Maven Plugin to load the configuration
The configuration loaded can then be used as properties in your POM. We are basically dynamically creating properties of our build. To do so (to use these properties), the steps above must be executed as early as possible in the build flow (i.e. validate or initialize phase).
Below an example of flow, just tested and work perfectly (on Windows machine):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>generation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>retrieve-config</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>echo</executable>
<arguments>
<argument>jar.name=from-exec</argument>
<argument>></argument>
<argument>config.properties</argument>
</arguments>
<workingDirectory>${basedir}/src/main/resources/</workingDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<id>read-properties</id>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/src/main/resources/config.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>${jar.name}</finalName>
</configuration>
</plugin>
</plugins>
</build>
</project>
Basically, the exec plugin attached to the validate phase will be executed at the beginning of the build, writing to a config.properties file (via the echo command) the content jar.name=from-exec.
Then the properties plugin attached to the initialize phase will read that config.properties file and load the properties to be used as part of the build.
Then, as an example, the jar plugin will use that property as part of its configuration (the <finalName>${jar.name}</finalName> part).
Running mvn clean package, you will find the from-exec.jar file in the target folder.
If you can't get a way of having the result of git describe as name=value pattern, you can (worst case) have two Exec Maven Plugin executions, the first writing to the file the property name and the equals character (i.e. via an echo), the second (git describe) appending to the file the property value.
There is a Maven plugin here https://github.com/ktoso/maven-git-commit-id-plugin that will do what you want.
If you hook into your build it will generate a Maven variable named ${git.commit.id.describe} that you can then use Maven's resource filtering to dynamically modify your manifest.
Building on what #A_Di-Matteo said, you can get the git tag into the properties file like this
In the maven exec plugin.
<execution>
<id>set-git-tag</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>bash</executable>
<arguments>
<argument>-c</argument>
<argument>echo git.tag=`git describe --always --dirty=-modified`</argument>
<argument>></argument>
<argument>config.properties</argument>
</arguments>
<workingDirectory>${basedir}/src/main/resources/</workingDirectory>
</configuration>
</execution>
You can also append to an existing file like so
<execution>
<id>set-git-tag</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>bash</executable>
<arguments>
<argument>-c</argument>
<argument>echo git.tag=`git describe --always --dirty=-modified`</argument>
<argument>>></argument>
<argument>${basedir}/src/main/resources/config.properties</argument>
</arguments>
</configuration>
</execution>
The limitation here is that it requires bash.
Is the wsdlDirectory setting in maven supposed to have an effect? I am finding that the setting:
<wsdlDirectory>${basedir}/src/main/resources/wsdl/</wsdlDirectory>
has no effect.
Executing the command below
mvn -X clean:clean jaxws:wsimport
always results in the output below, unless the wsdl files are moved to /home/projects/amazon/fps/trunk/src/wsdl
[DEBUG] The wsdl Directory is /home/projects/amazon/fps/trunk/src/wsdl
[DEBUG] The binding Directory is
/home/projects/amazon/fps/trunk/src/jaxws
[DEBUG] The wsdl Directory
is /home/projects/amazon/fps/trunk/src/wsdl
[INFO] Nothing to do, no
WSDL found!
I am using 2.2.1 on my Debian build machine and Embedded maven 3.0.2 on my Windows 7 Eclipse environment.
My pom.xml is as follows (irrelevant bits removed):
<project xmlns="..." xmlns:xsi="..." xsi:schemaLocation="...">
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>AmazonFPSImport</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>
${basedir}/src/main/resources/wsdl/
</wsdlDirectory>
<wsdlFiles>
<wsdlFile>AmazonFPS.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/wsdl/AmazonFPS.wsdl</wsdlLocation>
<sourceDestDir>
${basedir}/target/generated-sources/amazon/
</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Try moving the configuration section outside the <execution> tags. Or, bind to a specific phase
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>