2
votes

I need to execute JMeter tests on an offline server.

Currently, I have a Maven project which executes JMeter tests with the plugin "jmeter-maven-plugin" on my workstation.

Now I want to package this Maven project to deploy it on my offline server. I would like to be able to use the "maven verify" command on the deployed project to launch my JMeter tests.

I tried to package (zip) my projet with "maven-dependency-plugin" and "maven-assembly-plugin" plugins.

I want all the Maven dependencies in the zip file in order to execute my Maven project (especially the jmeter maven plugin) on my offline server.

It works, my dependencies are in my zip. But when I execute the following command on my server:

 mvn -o -Dmaven.repo.local=testj-meter-0.0.1-SNAPSHOT/libs/ verify

I have the following error:

[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building nsis test performance jmeter 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [WARNING] The POM for org.apache.maven.plugins:maven-resources-plugin:jar:2.6 is missing, no dependency information available [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.130 s [INFO] Finished at: 2018-02-27T14:54:34+01:00 [INFO] Final Memory: 8M/106M [INFO] ------------------------------------------------------------------------ [ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.apache.maven.plugins:maven-resources-plugin:jar:2.6 has not been downloaded from it before. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

My pom.xml and assemble.xml are the following:

Pom.xml :

<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>test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>jmeter tests</name>
  <description>jmeter tests</description>

    <properties>
        <plugin.jmeter.version>2.6.0</plugin.jmeter.version>
        <plugin.maven.dependency.version>2.10</plugin.maven.dependency.version>
    </properties>

    <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>${plugin.jmeter.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>${plugin.maven.dependency.version}</version>   
            </plugin>
        </plugins>
    </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <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.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>${plugin.maven.dependency.version}</version>
                <executions>
                  <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                      <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                      <outputDirectory>${project.build.directory}/libs</outputDirectory>
                      <useRepositoryLayout>true</useRepositoryLayout>
                      <copyPom>true</copyPom>
                      <addParentPoms>true</addParentPoms>
                      <excludeTransitive>false</excludeTransitive>
                    </configuration>
                  </execution>
                </executions>
              </plugin> 
             <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <descriptor>src/assembly/assemble.xml</descriptor>
                </configuration>
                <executions>
                    <execution>
                        <id>create-archive</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>             
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>${plugin.jmeter.version}</version>
            <type>jar</type>
            </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>${plugin.maven.dependency.version}</version>
            <type>jar</type>
            <exclusions>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>   
    </dependencies>
</project>

Assemble.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <id>src</id>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.basedir}</directory>
      <includes>
        <include>pom.xml</include>
      </includes>
      <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
      <directory>${project.basedir}/src/test/jmeter</directory>
      <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
        <directory>${project.basedir}/target/libs</directory>
        <outputDirectory>libs</outputDirectory>
    </fileSet>
  </fileSets>
</assembly>

Does anyone know where it comes from? I guess it is because the dependencies are not like they are in my local repository... although I mentioned the "copyPom" parameter in the maven dependencies plugin.

Thanks a lot, Hejk

2

2 Answers

0
votes

Not easy:

  1. First of all you will need to get all project dependencies locally. Can be done in several ways, for example by setting up your local maven repo or managing artifacts within a project. In both cases you also need to change settings.xml to make sure artifact resolution defaults to your local repo.

  2. You also need to make sure plug-ins are loaded from local repo. So you need to get all Maven standard build plug-ins, including jmeter-maven-plugin into your local repo sort of like this, but you will have to figure out the whole list of plug-ins you need to install.

After all that it should work, as long as you maintain your local repo.

Although I think in such case you are not getting any benefit from using jmeter-maven-plugin or Maven (main purpose of Maven is to help you avoid managing dependencies, which you have to do anyways).

Instead, I think it would be better to

  1. Create a Java "main", which launches JMeter tests, here's an example
  2. Use Maven on "online" server, to build it into jar with dependencies (which, btw, you are already trying to do by using maven-dependency-plugin)
  3. Run that jar from command line on your offline server to run tests. Maven or online dependencies won't be needed.
0
votes
  1. create a take-to-offline-server repository on server with internet access: mvn dependency:go-offline
  2. copy the repository somewhere on offline server
  3. edit settings.xml of maven on offline server and add a mirror like this:

    <mirror>
    <id>local</id>
    <mirrorOf>*</mirrorOf>
    <url>file:///tmp/local-repo</url>
    </mirror>
    

Now any mvn-command you could run on server with internet access, would be run on offline server with no error.