How to run a LoadFromFile command using pom.xml in MAVEN? - maven

I am working on a tool called Windchill. I have prepared a build to load few attributes through xml files.To load these xml files i use the following command.
For eg: windchill wt.load.LoadFromFile -d C:\ptc\Windchill_10.1\Windchill\loadFiles\pdmlink\itc\attributes\Attributes.xml -u wcadmin -p wcadmin
Like this I have some 100 commands to run manually on the windchill command prompt. So I basically want to automate the process by executing these commands sequentially using MAVEN without any much of manual work.
Is there any way to deploy this build. Please help.
Thanks.

I would suggest to take a look at the exec-maven-plugin which seemed to be the right choice for what you like to achieve.
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
...
<phase>WhatEver</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill </executable>
<!-- optional -->
<workingDirectory>/tmp</workingDirectory>
<arguments>
<argument>wt.load.LoadFromFile</argument>
<argument>and so on</argument>
...
</arguments>
</configuration>
</plugin>
</plugins>
</build>
...
</project>

<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>Build</groupId>
<artifactId>Build_SMB</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>SMB PROJECT</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill</executable>
<!-- optional -->
<workingDirectory>C:/mvn/test</workingDirectory>
<arguments>
<argument>wt.load.LoadFromFile</argument>
<argument>-d</argument>
<argument>C:/ptc/Windchill_10.1/Windchill/loadFiles/pdmlink/itc/attributes/Attributes.xml</argument>
<argument>-u</argument>
<argument>wcadmin</argument>
<argument>-p</argument>
<argument>wcadmin</argument>
</arguments>
<systemProperties>
<systemProperty>
<key>WT_HOME</key>
<value>${env.WT_HOME}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>

Related

How to run multiple jmeter .jmx tests with multiple input files using jmeter.maven.plugin

I need to be able to run jmeter tests from jenkins using mvn and jmeter-maven-plugin.
Here is the file setup:
test_dev.jmx
test_dev.txt
test_dev_regression.jmx
test_dev_regression.txt
Here is the pom file used by the mvn command (below):
<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.example</groupId>
<artifactId>JmeterTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>JMeter Example </name>
<properties>
<input.jmx.folder>${project.basedir}/src/test/jmeter</input.jmx.folder>
<input.jmx.file>test_${Environment}.jmx</input.jmx.file>
<input.csv>${project.basedir}/src/test/jmeter/test_${Environment}.txt</input.csv>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.9.0</version>
<configuration>
<propertiesUser>
<threadgroup00.dataFile>${input.csv}</threadgroup00.dataFile>
</propertiesUser>
<testFilesIncluded>
<!-- If spcified, only particular file will be processed. -->
<jMeterTestFile>${input.jmx.file}</jMeterTestFile>
</testFilesIncluded>
<testResultsTimestamp>false</testResultsTimestamp>
<!-- This will pick up all the jmx file at below folder. -->
<testFilesDirectory>${input.jmx.folder}</testFilesDirectory>
<generateReports>true</generateReports>
<resultsFileFormat>csv</resultsFileFormat>
</configuration>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>test</phase>
<goals>
<goal>jmeter</goal>
<goal>results</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
And here is the command we are using to run the tests:
mvn verify -DEnvironment=$TEST_ENVIRONMENT
As you can see, currently there are no regression tests being run. I'd like to add the regression test and it's input file into this pom so that both tests get run one after the other. The hang-up for me is the <threadgroup00.dataFile> property. What needs to be specified here to use another input file for the regression test? Or is there another way to run multiple tests with multiple inputs using this framework?
Thanks in advance!
As of version 3.0.0 you should now be able to do this, an example execution block showing the setup is:
<executions>
<execution>
<id>configuration-one</id>
<goals>
<goal>configure</goal>
</goals>
<configuration>
<resultsFileFormat>xml</resultsFileFormat>
</configuration>
</execution>
<execution>
<id>configuration-two</id>
<goals>
<goal>configure</goal>
</goals>
<configuration>
<resultsFileFormat>csv</resultsFileFormat>
</configuration>
</execution>
<execution>
<id>performance test one</id>
<goals>
<goal>jmeter</goal>
</goals>
<configuration>
<selectedConfiguration>configuration-one</selectedConfiguration>
<testFilesIncluded>
<jMeterTestFile>test1.jmx</jMeterTestFile>
</testFilesIncluded>
</configuration>
</execution>
<execution>
<id>performance test two</id>
<goals>
<goal>jmeter</goal>
</goals>
<configuration>
<selectedConfiguration>configuration-two</selectedConfiguration>
<testFilesIncluded>
<jMeterTestFile>test2.jmx</jMeterTestFile>
</testFilesIncluded>
</configuration>
</execution>
</executions>
The IT test showing this behaviour (Which the above execution example was taken from) is available at here.

How to generate HTML file in Jmeter using GUI alone?

I want to generate HTML output for Jmeter test using GUI steps.
jmeter -n -t sometest.jmx -l abc.csv -e -o outputhtml
I want to include the step of generating html output just like simple Simple Data Writer listener in GUI.
I am using maven's plugin for jmeter and I can't specify html output in it. If I could put that step in the test then it can be easily automated.
Since version 2.2.0, html generation is built-in:
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/blob/master/CHANGELOG.md
Just add this in configuration element:
<generateReports>true</generateReports>
Here is an example of a 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.ubikloadpack.jmeter</groupId>
<artifactId>maven-generate-reports</artifactId>
<version>1.0.0</version>
<description>Check that report generation works</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<suppressJMeterOutput>false</suppressJMeterOutput>
<testFilesIncluded>
<testFilesIncluded>**/*.jmx</testFilesIncluded>
</testFilesIncluded>
<generateReports>true</generateReports>
</configuration>
<executions>
<execution>
<id>configure</id>
<goals>
<goal>configure</goal>
</goals>
</execution>
<execution>
<id>performance test</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
In order to generate JMeter HTML Reporting Dashboard via Maven you need to
Override JMeter properties for dashboard generation (i.e. switch reporting to csv format), example POM configuration would look like:
<jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format>
<jmeter.save.saveservice.bytes>true</jmeter.save.saveservice.bytes>
<jmeter.save.saveservice.label>true</jmeter.save.saveservice.label>
<jmeter.save.saveservice.latency>true</jmeter.save.saveservice.latency>
<jmeter.save.saveservice.response_code>true</jmeter.save.saveservice.response_code>
<jmeter.save.saveservice.response_message>true</jmeter.save.saveservice.response_message>
<jmeter.save.saveservice.successful>true</jmeter.save.saveservice.successful>
<jmeter.save.saveservice.thread_counts>true</jmeter.save.saveservice.thread_counts>
<jmeter.save.saveservice.thread_name>true</jmeter.save.saveservice.thread_name>
<jmeter.save.saveservice.time>true</jmeter.save.saveservice.time>
Generate the dashboard at the end of JMeter test execution via Maven Exec plugin like
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>2.2.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${basedir}/target/jmeter/bin/ApacheJMeter-3.2.jar</argument>
<argument>-g</argument>
<argument>${basedir}/target/jmeter/results/${maven.build.timestamp}-example.jtl</argument>
<argument>-o</argument>
<argument>${basedir}/target/dashboard</argument>
</arguments>
</configuration>
</plugin>

Can we automatically generate jmeter dashboard report with Maven-jmeter plugin with out any manual command

I am trying to generate jmeter dashboard report from maven. But for generating jmeter dashboard report, we have to fire a command,
jmeter -g /path/to/jtl/file -o /where/you/want/to/store/dashboard
But with maven can we do that? what i want is to remove all manual process of copying csv file and run command on local copy of jmeter.
You can do it via extra Exec Maven Plugin task as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>generate-report-dashboard</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<argument>/path/to/ApacheJMeter.jar</argument>
<argument>org.apache.jmeter.NewDriver</argument>
<argument>-g</argument>
<argument>/path/to/results.jtl</argument>
<argument>-o</argument>
<argument>/path/to/report/folder<argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
See Five Ways To Launch a JMeter Test without Using the JMeter GUI article for more information on different ways of kicking off a JMeter test without using GUI
Using last version of jmeter-maven-plugin it will be generated by default configuration.
Sample pom.xml that uses JMeter 3.3:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>training-project</name>
<url>http://maven.apache.org</url>
<dependencies>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.6.0</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<execution>
<id>jmeter-tests2</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
<configuration>
<generateReports>true</generateReports>
</configuration>
</plugin>
</plugins>
</build>
</project>

Set directory in Maven Antrun Plugin

I've downloaded jquery-ui to my webapp which has a build.xml for compressing and minifying.
Now I would like to run this build.xml from within my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<ant antfile="src/main/webapp/resources/js/jquery-ui/build/build.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
But now the behavior for this buildfile is wrong. It creates a dist folder on the wrong place. Here's thebuild.xml` from jquery-ui: https://github.com/jquery/jquery-ui/blob/master/build/build.xml
It creates the dist folder on the same place where pom.xml is (same place i run mvn clean package) and it should create it in src/main/webapp/resources/js/jquery-ui/build
Is it possible to run build.xml from a specified directory (working directory)?
Can't access the documentation for the Ant task: http://ant.apache.org/manual/CoreTasks/ant.html
EDIT: pom.xml
<?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.example.myproject</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>myproject</name>
<dependencies>
<!-- ... -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- ... -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>myproject</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<executable>make</executable>
<workingDirectory>src/main/webapp/resources/js/jquery</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<ant antfile="build.xml" dir="src/main/webapp/resources/js/jquery-ui/build" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
On running mvn clean package I'm getting the following errors in minify target of jquery-ui's build.xml:
[apply] build/minify-js.sh: Line 3: /home/danny/myproject/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js: File or directory not found
The correct path should be ${basedir}/src/main/webapp/resources/js/jquery-ui/build/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js instead of the above mentioned...
According to http://ant.apache.org/manual/Tasks/ant.html, you can use the dir attribute:
<mkdir dir="${project.build.directory}/jquery-ui" />
<ant antfile="src/main/webapp/resources/js/jquery-ui/build/build.xml" dir="${project.build.directory}/jquery-ui" />
On the other hand, are you really sure you want to create the build directory underneath your src directory? Shouldn't this go into target rather?
I would recommend to use the maven plugin instead of Ant calls. Based on the docs maven-minify-plugin to do what you need. The plugin can be found in Maven Central. And furthermore you will find the maven-plugin-documention how to use the maven-plugin.

How to use master pom file to checkout all modules of a web application and build all modules

I have a web application that relies on several modules. So to build it, I have a master pom.xml file. What I want this pom file to do is to checkout out all the modules.
below is my pom file.
<executions>
<execution>
<id>check-out-project1</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
<configuration>
<checkoutDirectory>${project.build.directory}/module1</checkoutDirectory>
<connectionUrl>scm:svn:svn://svnserver/svn/module1/trunk</connectionUrl>
<!--<developerConnection>scm:svn:svn://svnserver/svn/module1/trunk</developerConnection>!-->
<username>username</username>
<password>password</password>
</configuration>
</execution>
<execution>
<id>check-out-project2</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
<configuration>
<checkoutDirectory>${project.build.directory}/module1</checkoutDirectory>
<connectionUrl>scm:svn:svn://svnserver/svn/module1/trunk</connectionUrl>
<username>username</username>
<password>password</password>
</configuration>
</execution>
</executions>
I have tried mvn scm:checkout and mvn scm:checkout -check-out-project1 but it give me the error:
Cannot run checkout command : Can't load the scm provider. You need to define a connectionUrl parameter.
I don't understand why this is happening since I have the connectionUrl parameters defined inside the pom file already,the ideas point that I want to get to is having the pom file configured to be able to checkout multiple projects at the same time. Please let me know what I am doing wrong here, Thanks in Advance.
I found that if placing each of the checkouts into its own <execution> ... </execution> and within place the individual <configuration> ... </configuration> for them works. For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.4</version>
<executions>
<execution>
<id>repo1-dependency</id>
<phase>generate-sources</phase>
<configuration>
<connectionUrl>${my.repo1.url}</connectionUrl>
<scmVersion>${my.repo1.branch}</scmVersion>
<scmVersionType>branch</scmVersionType>
<checkoutDirectory>${project.build.directory}/${my.repo1}-${my.repo1.branch}</checkoutDirectory>
</configuration>
<goals>
<goal>checkout</goal>
</goals>
</execution>
<execution>
<id>repo2-dependency</id>
<phase>generate-sources</phase>
<configuration>
<connectionUrl>${my.repo2.url}</connectionUrl>
<scmVersion>${my.repo2.branch}</scmVersion>
<scmVersionType>branch</scmVersionType>
<checkoutDirectory>${project.build.directory}/${my.repo2}-${my.repo2.branch}</checkoutDirectory>
</configuration>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
</plugin>
I faced to same situation and I found a solution -using your code :D- that works on my computer:
<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>de.xxx.internet</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Quick Start Archetype</name>
<url>http://www.mySite.de</url>
<scm>
<connection>scm:svn:http://svn-repo-adress:8080/repo/myDirectory</connection>
<developerConnection>http://svn-repo-adress:8080/repo/myDirectory</developerConnection>
<tag>HEAD</tag>
<url>http://svn-repo-adress:8080/repo/myDirectory</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.6</version>
<configuration>
<goals>checkout</goals>
<checkoutDirectory>target/checkout</checkoutDirectory>
<username>username</username>
<password>userpassword</password>
</configuration>
<executions>
<execution>
<id>check-out-project1</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
After I executed "mvn scm:checkout" on the cmd console it did work.
I think the important point was to add the scm tag first, before I had executed the build tag.

Resources