如何通过源码生成Gatling可执行工具

时间:2022-11-13 22:51:27

其实,这个对于不是很熟系sbt的人来说,或者对scala语言没有什么了解的人,接触Gatling这个开源的性能测试框架,还是有些茫然的。

因为GitHub上提供的Gatling (最新版本:2.2.0 snapshot)是源码,而且,完整的Gatling被拆分为Gatling(Core,相当于测试引擎吧)和Gatling-highchats(主要是用来生成测试报告)两部分。不知到为何要拆分为两部分,也许是因为Gatling-highchats部分引用了特殊license的软件插件(HighCharts & HighStock, 来自于HighSoft公司。。。)

1. 首先,从github上clone下gatling的源码。

git clone http://github.com/gatling/gatling

git clone http://github.com/gatling/gatling-highcharts

待这些文件都下载到本地后,先进入gatling的目录,在命令行下执行 sbt compile (,若你的系统下没有安装SBT,请先自己安装,我是直接在SBT官网下载的0.13.9的版本,解压到local目录下,再在/etc/profile下配置一下环境变量,方便使用)。gatling文件列表如下:

-rw-r--r--  root root  Jan   : CONTRIBUTING.md
drwxr-xr-x root root Jan : gatling-app
drwxr-xr-x root root Jan : gatling-bundle
drwxr-xr-x root root Jan : gatling-charts
drwxr-xr-x root root Jan : gatling-commons
drwxr-xr-x root root Jan : gatling-compiler
drwxr-xr-x root root Jan : gatling-core
drwxr-xr-x root root Jan : gatling-http
drwxr-xr-x root root Jan : gatling-jdbc
drwxr-xr-x root root Jan : gatling-jms
drwxr-xr-x root root Jan : gatling-metrics
drwxr-xr-x root root Jan : gatling-recorder
drwxr-xr-x root root Jan : gatling-redis
drwxr-xr-x root root Jan : gatling-test-framework
-rwxr-xr-x root root Jan : make_credentials.sh
-rw-r--r-- root root Jan : pgp.sbt
drwxr-xr-x root root Jan : project
-rw-r--r-- root root Jan : README.md
drwxr-xr-x root root Jan : src
drwxr-xr-x root root Jan : target
-rwxr-xr-x root root Jan : trigger_build.py
-rw-r--r-- root root Jan : version.sbt

sbt compile执行完毕后(可能需要一段时间,因为有些依赖的库要下载),需要将其发布到ivy仓库中(你也可以发布到mave仓库):

sbt publishLocal

 [root@CloudGame gatling]# sbt publishLocal
[info] Loading global plugins from /root/.sbt/0.13/plugins
[info] Loading project definition from /mnt/workwps/gatling2.1.7/gatling/project
[info] Set current project to gatling-parent (in build file:/mnt/workwps/gatling2.1.7/gatling/)
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-compiler/target/gatling-compiler-2.2.-SNAPSHOT-sources.jar ...
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-core/target/gatling-core-2.2.-SNAPSHOT-sources.jar ...
[info] Done packaging.
[info] Done packaging.
SLF4J: The following set of substitute loggers may have been accessed
SLF4J: during the initialization phase. Logging calls during this
SLF4J: phase were not honored. However, subsequent logging calls to these
SLF4J: loggers will work as normally expected.
SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
SLF4J: org.eclipse.aether.internal.impl.DefaultRepositorySystem
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-commons/target/gatling-commons-2.2.-SNAPSHOT.pom
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-compiler/target/gatling-compiler-2.2.-SNAPSHOT.pom
[info] :: delivering :: io.gatling#gatling-commons;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-commons/target/ivy-2.2.-SNAPSHOT.xml
[info] :: delivering :: io.gatling#gatling-compiler;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-compiler/target/ivy-2.2.-SNAPSHOT.xml
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-core/target/gatling-core-2.2.-SNAPSHOT.pom
[info] :: delivering :: io.gatling#gatling-core;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-core/target/ivy-2.2.-SNAPSHOT.xml
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-metrics/target/gatling-metrics-2.2.-SNAPSHOT.pom
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-redis/target/gatling-redis-2.2.-SNAPSHOT.pom
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-charts/target/gatling-charts-2.2.-SNAPSHOT.pom
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-jms/target/gatling-jms-2.2.-SNAPSHOT.pom
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-http/target/gatling-http-2.2.-SNAPSHOT.pom
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-jdbc/target/gatling-jdbc-2.2.-SNAPSHOT.pom
[info] :: delivering :: io.gatling#gatling-metrics;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-metrics/target/ivy-2.2.-SNAPSHOT.xml
[info] :: delivering :: io.gatling#gatling-jms;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-jms/target/ivy-2.2.-SNAPSHOT.xml
[info] :: delivering :: io.gatling#gatling-charts;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-charts/target/ivy-2.2.-SNAPSHOT.xml
[info] :: delivering :: io.gatling#gatling-redis;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-redis/target/ivy-2.2.-SNAPSHOT.xml
[info] :: delivering :: io.gatling#gatling-jdbc;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-jdbc/target/ivy-2.2.-SNAPSHOT.xml
[info] :: delivering :: io.gatling#gatling-http;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-http/target/ivy-2.2.-SNAPSHOT.xml
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-bundle/target/gatling-bundle-2.2.-SNAPSHOT.pom
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/target/gatling-parent-2.2.-SNAPSHOT.pom
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-app/target/gatling-app-2.2.-SNAPSHOT.pom
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-recorder/target/gatling-recorder-2.2.-SNAPSHOT.pom
[info] :: delivering :: io.gatling#gatling-bundle;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-bundle/target/ivy-2.2.-SNAPSHOT.xml
[info] :: delivering :: io.gatling#gatling-app;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-app/target/ivy-2.2.-SNAPSHOT.xml
[info] :: delivering :: io.gatling#gatling-parent;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/target/ivy-2.2.-SNAPSHOT.xml
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-compiler/target/gatling-compiler-2.2.-SNAPSHOT.jar ...
[info] published gatling-bundle to /root/.ivy2/local/io.gatling/gatling-bundle/2.2.-SNAPSHOT/poms/gatling-bundle.pom
[info] Done packaging.
[info] published gatling-bundle to /root/.ivy2/local/io.gatling/gatling-bundle/2.2.-SNAPSHOT/zips/gatling-bundle-bundle.zip
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-bundle/2.2.-SNAPSHOT/ivys/ivy.xml
[info] :: delivering :: io.gatling#gatling-recorder;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-recorder/target/ivy-2.2.-SNAPSHOT.xml
[info] Wrote /mnt/workwps/gatling2.1.7/gatling/gatling-test-framework/target/gatling-test-framework-2.2.-SNAPSHOT.pom
[info] published gatling-parent to /root/.ivy2/local/io.gatling/gatling-parent/2.2.-SNAPSHOT/poms/gatling-parent.pom
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-parent/2.2.-SNAPSHOT/ivys/ivy.xml
[info] published gatling-commons to /root/.ivy2/local/io.gatling/gatling-commons/2.2.-SNAPSHOT/poms/gatling-commons.pom
[info] published gatling-commons to /root/.ivy2/local/io.gatling/gatling-commons/2.2.-SNAPSHOT/jars/gatling-commons.jar
[info] published gatling-commons to /root/.ivy2/local/io.gatling/gatling-commons/2.2.-SNAPSHOT/srcs/gatling-commons-sources.jar
[info] published gatling-commons to /root/.ivy2/local/io.gatling/gatling-commons/2.2.-SNAPSHOT/docs/gatling-commons-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-commons/2.2.-SNAPSHOT/ivys/ivy.xml
[info] published gatling-compiler to /root/.ivy2/local/io.gatling/gatling-compiler/2.2.-SNAPSHOT/poms/gatling-compiler.pom
[info] published gatling-compiler to /root/.ivy2/local/io.gatling/gatling-compiler/2.2.-SNAPSHOT/jars/gatling-compiler.jar
[info] published gatling-compiler to /root/.ivy2/local/io.gatling/gatling-compiler/2.2.-SNAPSHOT/srcs/gatling-compiler-sources.jar
[info] published gatling-compiler to /root/.ivy2/local/io.gatling/gatling-compiler/2.2.-SNAPSHOT/docs/gatling-compiler-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-compiler/2.2.-SNAPSHOT/ivys/ivy.xml
[info] :: delivering :: io.gatling#gatling-test-framework;2.2.-SNAPSHOT :: 2.2.-SNAPSHOT :: integration :: Fri Jan :: CST
[info] delivering ivy file to /mnt/workwps/gatling2.1.7/gatling/gatling-test-framework/target/ivy-2.2.-SNAPSHOT.xml
[info] Main Scala API documentation to /mnt/workwps/gatling2.1.7/gatling/gatling-jms/target/api...
[info] Main Scala API documentation to /mnt/workwps/gatling2.1.7/gatling/gatling-jdbc/target/api...
[info] Main Scala API documentation to /mnt/workwps/gatling2.1.7/gatling/gatling-charts/target/api...
[info] Main Scala API documentation to /mnt/workwps/gatling2.1.7/gatling/gatling-metrics/target/api...
model contains documentable templates
model contains documentable templates
[info] Main Scala API documentation successful.
[info] Main Scala API documentation to /mnt/workwps/gatling2.1.7/gatling/gatling-redis/target/api...
model contains documentable templates
[info] Main Scala API documentation successful.
[info] Main Scala API documentation to /mnt/workwps/gatling2.1.7/gatling/gatling-http/target/api...
model contains documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-jdbc/target/gatling-jdbc-2.2.-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-core/target/gatling-core-2.2.-SNAPSHOT.jar ...
[info] Done packaging.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-metrics/target/gatling-metrics-2.2.-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-redis/target/gatling-redis-2.2.-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] published gatling-core to /root/.ivy2/local/io.gatling/gatling-core/2.2.-SNAPSHOT/poms/gatling-core.pom
[info] published gatling-core to /root/.ivy2/local/io.gatling/gatling-core/2.2.-SNAPSHOT/jars/gatling-core.jar
[info] published gatling-core to /root/.ivy2/local/io.gatling/gatling-core/2.2.-SNAPSHOT/srcs/gatling-core-sources.jar
[info] published gatling-core to /root/.ivy2/local/io.gatling/gatling-core/2.2.-SNAPSHOT/docs/gatling-core-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-core/2.2.-SNAPSHOT/ivys/ivy.xml
[info] published gatling-jdbc to /root/.ivy2/local/io.gatling/gatling-jdbc/2.2.-SNAPSHOT/poms/gatling-jdbc.pom
[info] published gatling-jdbc to /root/.ivy2/local/io.gatling/gatling-jdbc/2.2.-SNAPSHOT/jars/gatling-jdbc.jar
[info] published gatling-jdbc to /root/.ivy2/local/io.gatling/gatling-jdbc/2.2.-SNAPSHOT/srcs/gatling-jdbc-sources.jar
[info] published gatling-jdbc to /root/.ivy2/local/io.gatling/gatling-jdbc/2.2.-SNAPSHOT/docs/gatling-jdbc-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-jdbc/2.2.-SNAPSHOT/ivys/ivy.xml
[info] published gatling-redis to /root/.ivy2/local/io.gatling/gatling-redis/2.2.-SNAPSHOT/poms/gatling-redis.pom
[info] published gatling-redis to /root/.ivy2/local/io.gatling/gatling-redis/2.2.-SNAPSHOT/jars/gatling-redis.jar
[info] published gatling-redis to /root/.ivy2/local/io.gatling/gatling-redis/2.2.-SNAPSHOT/srcs/gatling-redis-sources.jar
[info] published gatling-redis to /root/.ivy2/local/io.gatling/gatling-redis/2.2.-SNAPSHOT/docs/gatling-redis-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-redis/2.2.-SNAPSHOT/ivys/ivy.xml
[info] published gatling-metrics to /root/.ivy2/local/io.gatling/gatling-metrics/2.2.-SNAPSHOT/poms/gatling-metrics.pom
[info] published gatling-metrics to /root/.ivy2/local/io.gatling/gatling-metrics/2.2.-SNAPSHOT/jars/gatling-metrics.jar
[info] published gatling-metrics to /root/.ivy2/local/io.gatling/gatling-metrics/2.2.-SNAPSHOT/srcs/gatling-metrics-sources.jar
[info] published gatling-metrics to /root/.ivy2/local/io.gatling/gatling-metrics/2.2.-SNAPSHOT/docs/gatling-metrics-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-metrics/2.2.-SNAPSHOT/ivys/ivy.xml
[info] Main Scala API documentation to /mnt/workwps/gatling2.1.7/gatling/gatling-app/target/api...
model contains documentable templates
[info] Main Scala API documentation successful.
[info] Main Scala API documentation to /mnt/workwps/gatling2.1.7/gatling/gatling-recorder/target/api...
[info] Main Scala API documentation successful.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-jms/target/gatling-jms-2.2.-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-app/target/gatling-app-2.2.-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] published gatling-jms to /root/.ivy2/local/io.gatling/gatling-jms/2.2.-SNAPSHOT/poms/gatling-jms.pom
[info] published gatling-jms to /root/.ivy2/local/io.gatling/gatling-jms/2.2.-SNAPSHOT/jars/gatling-jms.jar
[info] published gatling-jms to /root/.ivy2/local/io.gatling/gatling-jms/2.2.-SNAPSHOT/srcs/gatling-jms-sources.jar
[info] published gatling-jms to /root/.ivy2/local/io.gatling/gatling-jms/2.2.-SNAPSHOT/docs/gatling-jms-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-jms/2.2.-SNAPSHOT/ivys/ivy.xml
[info] published gatling-app to /root/.ivy2/local/io.gatling/gatling-app/2.2.-SNAPSHOT/poms/gatling-app.pom
[info] published gatling-app to /root/.ivy2/local/io.gatling/gatling-app/2.2.-SNAPSHOT/jars/gatling-app.jar
[info] published gatling-app to /root/.ivy2/local/io.gatling/gatling-app/2.2.-SNAPSHOT/srcs/gatling-app-sources.jar
[info] published gatling-app to /root/.ivy2/local/io.gatling/gatling-app/2.2.-SNAPSHOT/docs/gatling-app-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-app/2.2.-SNAPSHOT/ivys/ivy.xml
[info] Main Scala API documentation to /mnt/workwps/gatling2.1.7/gatling/gatling-test-framework/target/api...
model contains documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-test-framework/target/gatling-test-framework-2.2.-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] published gatling-test-framework to /root/.ivy2/local/io.gatling/gatling-test-framework/2.2.-SNAPSHOT/poms/gatling-test-framework.pom
[info] published gatling-test-framework to /root/.ivy2/local/io.gatling/gatling-test-framework/2.2.-SNAPSHOT/jars/gatling-test-framework.jar
[info] published gatling-test-framework to /root/.ivy2/local/io.gatling/gatling-test-framework/2.2.-SNAPSHOT/srcs/gatling-test-framework-sources.jar
[info] published gatling-test-framework to /root/.ivy2/local/io.gatling/gatling-test-framework/2.2.-SNAPSHOT/docs/gatling-test-framework-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-test-framework/2.2.-SNAPSHOT/ivys/ivy.xml
model contains documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-charts/target/gatling-charts-2.2.-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] published gatling-charts to /root/.ivy2/local/io.gatling/gatling-charts/2.2.-SNAPSHOT/poms/gatling-charts.pom
[info] published gatling-charts to /root/.ivy2/local/io.gatling/gatling-charts/2.2.-SNAPSHOT/jars/gatling-charts.jar
[info] published gatling-charts to /root/.ivy2/local/io.gatling/gatling-charts/2.2.-SNAPSHOT/srcs/gatling-charts-sources.jar
[info] published gatling-charts to /root/.ivy2/local/io.gatling/gatling-charts/2.2.-SNAPSHOT/docs/gatling-charts-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-charts/2.2.-SNAPSHOT/ivys/ivy.xml
model contains documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-recorder/target/gatling-recorder-2.2.-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] published gatling-recorder to /root/.ivy2/local/io.gatling/gatling-recorder/2.2.-SNAPSHOT/poms/gatling-recorder.pom
[info] published gatling-recorder to /root/.ivy2/local/io.gatling/gatling-recorder/2.2.-SNAPSHOT/jars/gatling-recorder.jar
[info] published gatling-recorder to /root/.ivy2/local/io.gatling/gatling-recorder/2.2.-SNAPSHOT/srcs/gatling-recorder-sources.jar
[info] published gatling-recorder to /root/.ivy2/local/io.gatling/gatling-recorder/2.2.-SNAPSHOT/docs/gatling-recorder-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-recorder/2.2.-SNAPSHOT/ivys/ivy.xml
model contains documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /mnt/workwps/gatling2.1.7/gatling/gatling-http/target/gatling-http-2.2.-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] published gatling-http to /root/.ivy2/local/io.gatling/gatling-http/2.2.-SNAPSHOT/poms/gatling-http.pom
[info] published gatling-http to /root/.ivy2/local/io.gatling/gatling-http/2.2.-SNAPSHOT/jars/gatling-http.jar
[info] published gatling-http to /root/.ivy2/local/io.gatling/gatling-http/2.2.-SNAPSHOT/srcs/gatling-http-sources.jar
[info] published gatling-http to /root/.ivy2/local/io.gatling/gatling-http/2.2.-SNAPSHOT/docs/gatling-http-javadoc.jar
[info] published ivy to /root/.ivy2/local/io.gatling/gatling-http/2.2.-SNAPSHOT/ivys/ivy.xml
[success] Total time: s, completed Jan , :: PM

这个过程,比较像mvn install将生成的模块安装到本地.m2仓库中的过程。到此,gatling引擎部分编译和发布完成。

然后,进入gatling-highchats,和上述编译gatling的过程类似,执行sbt compile,然后在发布到本地ivy仓库。注意,一定要先对gatling进行发布后再编译gatling-highchats,否则在编译gatling-highchats的时候会报错的,找不到依赖的库

至此,编译部分都完成了,那么,问题来了,生成的工具(可执行文件)在什么地方呢?在什么地方可以执行刚才生成的工具呢?官网上说的比较清楚,我也倾向于用bundle的文件来执行。默认情况下,这个文件会在ivy的仓库里面。就拿我的环境来说,其目录如下:

 [root@CloudGame zips]# pwd
/root/.ivy2/local/io.gatling.highcharts/gatling-charts-highcharts-bundle/2.2.-SNAPSHOT/zips

文件内容如下:

 [root@CloudGame gatling-charts-highcharts-bundle-2.2.-SNAPSHOT]# ll
total
drwxr-xr-x root root Jan : bin
drwxr-xr-x root root Jan : lib
-rw-r--r-- root root Jan : LICENSE
drwxr-xr-x root root Jan : results
drwxr-xr-x root root Jan : user-files
[root@CloudGame gatling-charts-highcharts-bundle-2.2.-SNAPSHOT]# cd bin/
[root@CloudGame bin]# ll
total
-rwxr--r-- root root Jan : gatling.bat
-rwxr--r-- root root Jan : gatling.sh
-rwxr--r-- root root Jan : recorder.bat
-rwxr--r-- root root Jan : recorder.sh

上面加黑的目录,就是我们想要的被解压后的目录,里面有我们期待的内容:

 [root@CloudGame gatling-bundle-2.2.-SNAPSHOT]# ll
total
drwxr-xr-x root root Jan : bin
-rw-r--r-- root root Jan : LICENSE
drwxr-xr-x root root Jan : results
drwxr-xr-x root root Jan : user-files
[root@CloudGame gatling-bundle-2.2.-SNAPSHOT]# cd bin/
[root@CloudGame bin]# ll
total
-rwxr-xr-x root root Jan : gatling.bat
-rwxr-xr-x root root Jan : gatling.sh
-rwxr-xr-x root root Jan : recorder.bat
-rwxr-xr-x root root Jan : recorder.sh

到这里,可以说从源码生成gatling的过程结束了!

在此,我要说明一点就是,2.2.0-SNAPSHOT的版本,比较新,里面有些api是JDK8的,所以,在编译运行的时候,保证你的环境是jdk8哟,否则会出现下面的错误:

 [root@CloudGame bin]# ./recorder.sh
GATLING_HOME is set to /root/.ivy2/local/io.gatling.highcharts/gatling-charts-highcharts-bundle/2.2.-SNAPSHOT/zips/gatling-charts-highcharts-bundle-2.2.-SNAPSHOT
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigRenderOptions : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:)
at java.net.URLClassLoader.access$(URLClassLoader.java:)
at java.net.URLClassLoader$.run(URLClassLoader.java:)
at java.net.URLClassLoader$.run(URLClassLoader.java:)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:)
at java.lang.ClassLoader.loadClass(ClassLoader.java:)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:)
at java.lang.ClassLoader.loadClass(ClassLoader.java:)
at io.gatling.recorder.config.RecorderConfiguration$.<init>(RecorderConfiguration.scala:)
at io.gatling.recorder.config.RecorderConfiguration$.<clinit>(RecorderConfiguration.scala)
at io.gatling.recorder.GatlingRecorder$.io$gatling$recorder$GatlingRecorder$$initRecorder(GatlingRecorder.scala:)
at io.gatling.recorder.GatlingRecorder$$anonfun$fromArgs$.apply(GatlingRecorder.scala:)
at io.gatling.recorder.GatlingRecorder$$anonfun$fromArgs$.apply(GatlingRecorder.scala:)
at scala.Option.map(Option.scala:)
at io.gatling.recorder.GatlingRecorder$.fromArgs(GatlingRecorder.scala:)
at io.gatling.recorder.GatlingRecorder$.main(GatlingRecorder.scala:)
at io.gatling.recorder.GatlingRecorder.main(GatlingRecorder.scala)

最后,测试一下源码来的工具是否可用,哈哈,看到recorder的启动界面了,如下图,说明一切正常!

如何通过源码生成Gatling可执行工具

附加一下设置项目的javaHome的命令,即相关的操作!

 gatling-parent > set every javaHome := sys.env.get("JAVA_HOME") map file
[info] Defining */*:javaHome
[info] The new value will be used by gatling-app/*:compilers, gatling-app/*:console::compilers and 125 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to gatling-parent (in build file:/mnt/workwps/gatling2.1.7/gatling/)
gatling-parent > show javaHome
[info] gatling-core/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-compiler/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-redis/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-metrics/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-commons/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-recorder/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-jms/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-app/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-test-framework/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-http/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-charts/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-bundle/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-jdbc/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
[info] gatling-parent/*:javaHome
[info] Some(/usr/java/jdk1.8.0_65)
gatling-parent >

OK,完工!