The requested class is not in classpath or does not extends Simulation

I am trying to upgrade to Gatling 2.1, but I’m stuck because I get this error when running gatling.sh:

`
The requested class(‘XxxYyyZzz’) can not be found in the classpath or does not extends Simulation.

Choose a simulation number:
[0] computerdatabase.BasicSimulation
[1] computerdatabase.advanced.AdvancedSimulationStep01
[2] computerdatabase.advanced.AdvancedSimulationStep02
[3] computerdatabase.advanced.AdvancedSimulationStep03
[4] computerdatabase.advanced.AdvancedSimulationStep04
[5] computerdatabase.advanced.AdvancedSimulationStep05

`

I tried echo’ing the $GATLING_CLASSPATH used in gatling.sh and it does include a directory where my compiled simulation script (here named ‘XxxYyyZzz’) is present in the form of a XxxYyyZzz.class file as well as a number of class files for inner classes etc.

The classpath is quite long, so I tried placing this particular directory in front, in case it was because the path was too long, but that didn’t change anything!

My invocation looks like this:

`
/path/to/gatling-charts-highcharts-bundle-2.1.4/bin/gatling.sh --simulation XxxYyyZzz --results-folder "$HERE/reports --data-folder “$HERE/data”

`

Any suggestions would be appreciated!!

Best regards
Ulrik

Are you sure you don’t miss the package?
Then, please provide a reproducer.

My class does not declare a package.
I actually tried adding a package in the scala file - and on the startup parameters - that changed nothing.

I guess you’re right, I should look into trying a minimal example and go from there…

/Ulrik

I tried copying the quickstart example to my performancetest/src folder:

`

package computerdatabase  // 1

import io.gatling.core.Predef._ // 2
import io.gatling.http.Predef._
import scala.concurrent.duration._

class MyBasicSimulation extends Simulation { // 3

  val httpConf = http // 4
    .baseURL("http://computer-database.herokuapp.com") // 5
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // 6
    .doNotTrackHeader("1")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0")

  val scn = scenario("BasicSimulation") // 7
    .exec(http("request_1")  // 8
    .get("/")) // 9
    .pause(5) // 10

  setUp( // 11
    scn.inject(atOnceUsers(1)) // 12
  ).protocols(httpConf) // 13
}

`

Then I compiled it with this command:

`
java -cp “$GATLING_HOME/lib/*” -Dscala.home="$GATLING_HOME/lib" -Dscala.usejavacp=true scala.tools.nsc.Main src/MyBasicSimulation.scala

`

Class files are now placed under my performancetest/computerdatabase/ folder:

`

ls performancetest/computerdatabase/
`
MyBasicSimulation.class

I modified the gatling.sh script to echo “$GATLING_CLASSPATH” the classpath just before invoking the Gatling class with a java command. This is my output:

`

GATLING_HOME is set to /products/gatling-charts-highcharts-bundle-2.1.4
Run compiler
Run Gatling
/products/gatling-charts-highcharts-bundle-2.1.4/lib/*:/products/gatling-charts-highcharts-bundle-2.1.4/user-files:/products/gatling-charts-highcharts-bundle-2.1.4/conf:/Users/usk/Work/FMK/fmk-recept/performancetest
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Xmx2048m
The requested class(‘computerdatabase.MyBasicSimulation’) can not be found in the classpath or does not extends Simulation.
Choose a simulation number:
[0] computerdatabase.BasicSimulation
[1] computerdatabase.advanced.AdvancedSimulationStep01
[2] computerdatabase.advanced.AdvancedSimulationStep02
[3] computerdatabase.advanced.AdvancedSimulationStep03
[4] computerdatabase.advanced.AdvancedSimulationStep04
[5] computerdatabase.advanced.AdvancedSimulationStep05
^C

`

What am I missing?

/Ulrik

Why don’t you let Gatling do the compiling job?

I tried the basic example again (with the src in a new folder separate from my previous attempts), and let gatling do the compiling itself and that worked fine!

But trying the same with my own Simulation classes, which make use of a lot of Java code references in the JAVA_CLASSPATH gave compile errors (.

Therefore I tried modifying gatling.sh with this line:

`

COMPILATION_CLASSPATH=$COMPILATION_CLASSPATH:$JAVA_CLASSPATH

`

… and the it all worked for my code too!

That must be an error in the gatling.sh script, or perhaps in the ZincCompiler, right?

That’s a bug in our compiler module that’s ignoring java files.
I’ll fix this, you shouldn’t have to compile yourself.

It seems this fix didn’t make into Gatling 2.1.5, right?

/Ulrik

Yes it did: https://github.com/gatling/gatling/issues/2640

Do you still have an issue? If so, can you share a reproducer please?

I still have an issue, yes.

It seems your fix has to do with the scala compiler including .java files.

I am trying to compile with my already compiled .class files in the JAVA_CLASSPATH.

My local fix is to add this line in gatling.sh, just before “# Run the compiler”:

COMPILATION_CLASSPATH=$COMPILATION_CLASSPATH:$JAVA_CLASSPATH

/Ulrik

Could be related to https://github.com/gatling/gatling/issues/2694