用于离线模式的包maven项目

问题描述 投票:0回答:2

我需要在离线服务器上执行JMeter测试。

目前,我有一个Maven项目,它在我的工作站上使用插件“jmeter-maven-plugin”执行JMeter测试。

现在我想打包这个Maven项目,将其部署在我的离线服务器上。我希望能够在已部署的项目上使用“maven verify”命令来启动我的JMeter测试。

我尝试使用“maven-dependency-plugin”和“maven-assembly-plugin”插件打包(zip)我的项目。

我想在zip文件中使用所有Maven依赖项,以便在我的离线服务器上执行我的Maven项目(尤其是jmeter maven插件)。

它有效,我的依赖是我的拉链。但是当我在我的服务器上执行以下命令时:

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

我有以下错误:

[INFO]扫描项目... [INFO] [INFO] ----------------------------------- ------------------------------------- [INFO]建立nsis测试性能jmeter 0.0.1-SNAPSHOT [INFO] ----------------------------------------------- ------------------------- [警告] org.apache.maven.plugins的pOM:maven-resources-plugin:jar:2.6丢失了,没有可用的依赖信息[INFO] ------------------------------------------ ------------------------------ [INFO] BUILD FAILURE [INFO] ------------ -------------------------------------------------- ---------- [INFO]总时间:0.130秒[INFO]完成时间:2018-02-27T14:54:34 + 01:00 [INFO]最终记忆:8M / 106M [INFO] - -------------------------------------------------- --------------------- [ERROR]插件org.apache.maven.plugins:maven-resources-plugin:2.6或其中一个依赖项无法解析:无法在离线模式下访问中央(https://repo.maven.apache.org/maven2)和工件org.apache.maven.plugins:maven-resources-plugin:jar:2.6还没有之前从它下载过。 - > [Help 1] [ERROR] [ERROR]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。 [ERROR]使用-X开关重新运行Maven以启用完整的调试日志记录。 [错误] [错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:[错误] [帮助1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

我的pom.xml和assemble.xml如下:

Pom.hml:

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

有谁知道它来自哪里?我想这是因为依赖关系不像它们在我的本地存储库中...虽然我在maven依赖项插件中提到了“copyPom”参数。

非常感谢,Hejk

maven jmeter maven-assembly-plugin maven-dependency-plugin
2个回答
0
投票

不容易:

  1. 首先,您需要在本地获取所有项目依赖项。可以通过多种方式完成,例如通过设置your local maven repomanaging artifacts within a project。在这两种情况下,您还需要更改settings.xml以确保工件分辨率默认为您的本地仓库。
  2. 您还需要确保从本地存储库加载插件。因此,您需要将所有Maven标准构建插件(包括jmeter-maven-plugin)添加到本地repo sort of like this中,但您必须弄清楚需要安装的整个插件列表。

毕竟它应该工作,只要你维护你的本地回购。

虽然我认为在这种情况下你没有从使用jmeter-maven-plugin或Maven中获得任何好处(Maven的主要目的是帮助你避免管理依赖关系,你必须要做的事情)。

相反,我认为这会更好

  1. 创建一个Java“main”,它启动JMeter测试,here's an example
  2. 在“在线”服务器上使用Maven,将其构建到具有依赖关系的jar中(顺便说一下,您已经尝试使用maven-dependency-plugin)
  3. 从脱机服务器上的命令行运行该jar以运行测试。不需要Maven或在线依赖。

0
投票
  1. 在具有Internet访问权限的服务器上创建一个脱机服务器存储库:mvn依赖:go-offline
  2. 在脱机服务器上的某处复制存储库
  3. 在离线服务器上编辑maven的settings.xml并添加如下镜像: <mirror> <id>local</id> <mirrorOf>*</mirrorOf> <url>file:///tmp/local-repo</url> </mirror>

现在,您可以在具有Internet访问权限的服务器上运行的任何mvn命令都可以在脱机服务器上运行而不会出现错误。

© www.soinside.com 2019 - 2024. All rights reserved.