I am trying to start mock server with mockserver-netty-5.13.2
from shell,
java version:
11.0.9
Rough shell code like this:
java -version
echo "start shell before java -jar line"
java -jar ./mockserver-netty-5.13.2.jar -serverPort 9090 -logLevel DEBUG &> ${DIR}/mockserver.log
The exception thrown from java -jar ./mockserver-netty-5.13.2.jar -serverPort 9090
Exception in thread "main" java.lang.NoClassDefFoundError: org/mockserver/version/Version
at org.mockserver.cli.Main.<clinit>(Main.java:27)
Caused by: java.lang.ClassNotFoundException: org.mockserver.version.Version
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
Has anyone run into this issue and resolved it ? Any help would be much appreciated !!!
I was able to replicate the problem within a very similar environment as yours. The issue is caused because your are using the wrong jar. To run the
mockserver
from the command line you should use a-shaded
jar, where it's dependencies are included. The jar you are using does not include the required dependencies and it is not supposed to be ran in the command line without providing them by hand as part of theclasspath
. The error you getpretty much supports this conclusion, and tells you that the
org.mockserver.version.Version
class is not provided when you run this specific jar.Here, is the official docs that indicate you should use the shaded jar to run mockserver from the command line.
Here you can download the mockserver
5.13.2
shaded jar. Then, run it like thisHope that helps!