# Pack simulation with dependencies in jar

**URL:** <https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406>\
**Category:** Gatling (Open-Source)\
**Created:** [June 4, 2013, 8:39am UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406 "2013-06-04T08:39:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy\_van\_der\_Valk](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roy\_van\_der\_Valk](https://community.gatling.io/u/Roy_van_der_Valk)\
**Post date:** [June 4, 2013, 8:39am UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/1 "2013-06-04T08:39:52Z")

</div>

Hi all,

I’m fairly new to programming - especially Scala - in general, but I’ve managed to work with Gatling (create custom feeders, save, re-use and edit elements from responses etc.) without any problem. So a big praise for the ease of use of your DSL, documentation and community!

Now that I set up a sufficient scenario to do some basic performance tests on our framework I want to run it on a server via one jar file including all dependencies. I managed to create a jar using the following [method](http://stackoverflow.com/questions/3384871/building-jar-with-maven-scala-plugin). If I run it I get the following IOException:

> _Exception in thread “main” java.lang.ExceptionInInitializerError_  
> _at Engine$delayedInit$body.apply(Engine.scala:7)_  
> _at scala.Function0$class.apply$mcV$sp(Function0.scala:34)_  
> _at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)_  
> _at scala.App$$anonfun$main$1.apply(App.scala:60)_  
> _at scala.App$$anonfun$main$1.apply(App.scala:60)_  
> _at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)_  
> _at scala.collection.immutable.List.foreach(List.scala:76)_  
> _at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)_  
> _at scala.App$class.main(App.scala:60)_  
> _at Engine$.main(Engine.scala:4)_  
> _at Engine.main(Engine.scala)_  
> _Caused by: java.io.IOException: The filename, directory name, or volume label syntax is incorrect_  
> _at java.io.WinNTFileSystem.canonicalize0(Native Method)_  
> _at java.io.Win32FileSystem.canonicalize(Unknown Source)_  
> _at java.io.File.getCanonicalPath(Unknown Source)_  
> _at scala.tools.nsc.io.Path.toCanonical(Path.scala:100)_  
> _at scala.tools.nsc.io.Path.isSame(Path.scala:228)_  
> _at scala.tools.nsc.io.Path.parents(Path.scala:173)_  
> _at IDEPathHelper$.(IDEPathHelper.scala:7)_  
> _at IDEPathHelper$.(IDEPathHelper.scala)_  
> _… 11 more_

I guess it has to do with the paths configured not being valid when running it from a jar. I still got the default paths configured in IDEPathHelper.scala

> _val gatlingConfUrl = getClass.getClassLoader.getResource(“application.conf”).getPath_  
> _val projectRootDir = File(gatlingConfUrl).parents(2)_
> 
> _val mavenSourcesDirectory = projectRootDir / “src” / “main” / “scala”_  
> _val mavenResourcesDirectory = projectRootDir / “src” / “main” / “resources”_  
> _val mavenTargetDirectory = projectRootDir / “target”_  
> _val mavenBinariesDirectory = mavenTargetDirectory / “main-classes”_
> 
> _val dataDirectory = mavenResourcesDirectory / “data”_  
> _val requestBodiesDirectory = mavenResourcesDirectory / “request-bodies”_
> 
> _val recorderOutputDirectory = mavenSourcesDirectory_  
> _val resultsDirectory = mavenTargetDirectory / “results”_

Anybody has experience with packing the whole simulation in an executable jar and can help me? Are there any best practices or examples for running simulations from a server?

Thanks in advance.

Roy

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [June 4, 2013, 9:08am UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/2 "2013-06-04T09:08:29Z")

</div>

Thanks for your kind words, much appreciated.

Loading resources from classpath just made it into master yesterday evening: [https://github.com/excilys/gatling/commit/b8d273a30d877a4b84e8df43f1c2bac199f0951d](https://github.com/excilys/gatling/commit/b8d273a30d877a4b84e8df43f1c2bac199f0951d)  
We have yet to investigate if it can be backported into 1.5 branch. Pierre, WDYT?

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Roy\_van\_der\_Valk](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roy\_van\_der\_Valk](https://community.gatling.io/u/Roy_van_der_Valk)\
**Post date:** [June 4, 2013, 9:30am UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/3 "2013-06-04T09:30:17Z")

</div>

Hi Stéphane,

Thanks for your quick reply! I don’t understand your answer completely.

Maybe it is better to phrase my question in more general terms.

1. I want to run my simulation from a server
2. Set some variables for the number of users and simulation time
3. Let it run for a couple of days  
I thought an executable jar would be the most handy solution, but maybe there are better solutions?

Roy

---

<div class="post-metadata">

**Author:** ![Chris\_Price](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@Chris\_Price](https://community.gatling.io/u/Chris_Price)\
**Post date:** [June 4, 2013, 2:06pm UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/4 "2013-06-04T14:06:24Z")

</div>

Roy,

It’s certainly possible to build an “uberjar” but sometimes it’s kind of a pain. How much control do you have over your server environment? Do you have the option of using “sbt” there?

I have a project where I have basically the same requirements that you’ve outlined and my solution was to launch the simulation using sbt. In my sbt build file I simply have a list of gatling dependencies (which are available from public maven repos) and a small configuration tweak that tells it the “main class” to run. sbt handles the downloading of all of the gatling jars and setting up the classpath. You could do the same thing with maven.

I also have a need for configuring the number of users/repetitions/etc., so I wrote a thin wrapper class that reads my configuration parameters (from environment variables and json files), instantiates the simulation objects, and then hands control back over to Gatling to run the sim.

If any of that sounds useful to you, let me know and I’ll be happy to pass along some example code.

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [June 4, 2013, 2:24pm UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/5 "2013-06-04T14:24:13Z")

</div>

What’s the problem with the standard bundle and launch scripts, then?

---

<div class="post-metadata">

**Author:** ![Roy\_van\_der\_Valk](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roy\_van\_der\_Valk](https://community.gatling.io/u/Roy_van_der_Valk)\
**Post date:** [June 5, 2013, 7:57am UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/6 "2013-06-05T07:57:24Z")

</div>

Sorry Stéphane, as I said I’m not a very experienced programmer. What is the standard way of deploying and launching your Gatling simulation on a server easily?

---

<div class="post-metadata">

**Author:** ![Roy\_van\_der\_Valk](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roy\_van\_der\_Valk](https://community.gatling.io/u/Roy_van_der_Valk)\
**Post date:** [June 5, 2013, 8:05am UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/7 "2013-06-05T08:05:06Z")

</div>

Hi Chris,

Thanks for you thinking with me here. Finally we want to use Gatling for more applications, so we want to automatize this process as much as possible. Why did you choose sbt over Maven? I guess Maven is the standard way Stéphane is mentioning (below), or am I wrong?

Anyway I’m very much interested in sbt and example code. Your solution sound very elegant.

Roy

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [June 5, 2013, 8:17am UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/8 "2013-06-05T08:17:35Z")

</div>

Just use the regular archive (zip or tar), decompress, drop your files in the expected user-files sub folders and launch the bat or sh script.  
Beware that if you want to run a very long simulation, you’ll have to edit the simulation timeout in conf/gatling.conf.

Have you read the documentation? [https://github.com/excilys/gatling/wiki/Getting-Started](https://github.com/excilys/gatling/wiki/Getting-Started)

---

<div class="post-metadata">

**Author:** ![Roy\_van\_der\_Valk](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roy\_van\_der\_Valk](https://community.gatling.io/u/Roy_van_der_Valk)\
**Post date:** [June 5, 2013, 9:28am UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/9 "2013-06-05T09:28:01Z")

</div>

Thank you! I will give it a try this week. I read the documentation thoroughly, but I didn’t relate the command line interface to running it on a server.

Sorry… as I said not much experience…

@Chris: I will also look into sbt though, sounds pretty handy and elegant.

---

<div class="post-metadata">

**Author:** ![Chris\_Price](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@Chris\_Price](https://community.gatling.io/u/Chris_Price)\
**Post date:** [June 5, 2013, 4:14pm UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/10 "2013-06-05T16:14:08Z")

</div>

Roy,

Definitely use the bundle approach that Stéphane mentions if it suits your needs.

For us, we have a lot of different servers we want to run on and we didn’t want to deal with copying the binaries around all over the place. The sbt / maven approach allows me to create a very small git repo that contains just the build.sbt and my simulation / user files, and then that git repo can be checked out on any machine and launched w/o having to manually copy around the binaries. You could accomplish the same thing in maven. Here’s (roughly) what my build.sbt looks like if anyone is interested 🙂

---

<div class="post-metadata">

**Author:** ![Roy\_van\_der\_Valk](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roy\_van\_der\_Valk](https://community.gatling.io/u/Roy_van_der_Valk)\
**Post date:** [June 6, 2013, 10:38am UTC](https://community.gatling.io/t/pack-simulation-with-dependencies-in-jar/406/11 "2013-06-06T10:38:13Z")

</div>

Thanks Chris! I will keep your solution in mind though, hopefully our performance testing efforts will one day grown to such a stage where this is necessary.
