ClassNotFoundException when running with jar file

2,427 views
Skip to first unread message

Amir Y

unread,
Aug 18, 2015, 7:29:48 AM8/18/15
to Gatling User Group
I get my code running correctly using maven on my local machine, example:

mvn gatling:execute -Dproperty1=value1 

Once I build the fat-jar, I can't get it running via this command:

java -DsimulationClass=simulations.ActualSimulationClass -Dproperty1=value1 -cp  ske-test-gatling-0.0.1-SNAPSHOT-jar-with-dependencies.jar StartSimulation

and the StartSimulation class goes like this

import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder

object Engine extends App {

  val props = new GatlingPropertiesBuilder
  props.dataDirectory(IDEPathHelper.dataDirectory.toString)
  props.resultsDirectory(IDEPathHelper.resultsDirectory.toString)
  props.bodiesDirectory(IDEPathHelper.bodiesDirectory.toString)
  props.binariesDirectory(IDEPathHelper.mavenBinariesDirectory.toString)

  Gatling.fromMap(props.build)
}


Here's the full stack trace:
developer@sit1b046-3:~/workspace/mp-nav-inntekt-gatling/target$ Exception in thread "main" java.lang.NoClassDefFoundError: scala/Function0
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getMethod0(Class.java:2856)
at java.lang.Class.getMethod(Class.java:1668)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: scala.Function0
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more


could anybody help please?

Versions:
scala.version: 2.11.6
gatling.version: 2.1.7
gatling-maven-plugin.version: 2.1.7
scala-maven-plugin.version: 3.2.0

Amir

Pierre DAL-PRA

unread,
Aug 18, 2015, 7:31:33 AM8/18/15
to gat...@googlegroups.com
Looks that the scala-library jar is missing from your fat JAR. Can you check that it's there ?

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Amir Y

unread,
Aug 18, 2015, 7:47:16 AM8/18/15
to Gatling User Group
Appreciate the prompt reply!

I get this by unzipping the jar file:
developer@sit1b046-3:~/workspace/mp-nav-inntekt-gatling/target$ unzip -l ske-test-gatling-0.0.1-SNAPSHOT-jar-with-dependencies.jar | grep -i scala
        0  2015-08-18 13:42   test/scala/
        0  2015-08-18 13:42   test/scala/conf/
        0  2015-08-18 13:42   test/scala/registry/
        0  2015-08-18 13:42   test/scala/simulations/
     1661  2011-11-04 19:38   org/codehaus/jackson/map/deser/std/StdScalarDeserializer.class
      342  2015-08-18 13:42   test/scala/conf/MPUriProvider.scala
      426  2015-08-18 13:42   test/scala/conf/MPNAVInntektHttpConf.scala
      484  2015-08-18 13:42   test/scala/registry/Registry.scala
      994  2011-11-04 19:38   org/codehaus/jackson/map/ser/ScalarSerializerBase.class
     1620  2011-11-04 19:38   org/codehaus/jackson/map/ser/std/NonTypedScalarSerializerBase.class
     2464  2015-08-18 13:42   test/scala/simulations/MPHentInntektSimulation.scala
      462  2015-08-18 13:42   test/scala/StartSimulation.scala
      799  2011-11-04 19:38   org/codehaus/jackson/map/deser/StdScalarDeserializer.class
     2406  2011-11-04 19:38   org/codehaus/jackson/map/ser/std/ScalarSerializerBase.class
      571  2015-08-18 13:42   test/scala/conf/TestSetup.scala


Except those few files under "org/codehaus/jackson/map/", the rest are all my own source files. So, yeah I guess I'm missing the scala library there.
What's the solution?

Amir

Pierre DAL-PRA

unread,
Aug 18, 2015, 7:50:13 AM8/18/15
to gat...@googlegroups.com
I think that the plugin packaging Gatling and the simulations in your fat JAR is configured incorrectly. Can't help much on that, I suggest that you have a look at that plugin's configuration to see how to package all your dependencies in your fat JAR.

Cheers,

Pierre
Reply all
Reply to author
Forward
0 new messages