I’m working on a project for school and I needed the Jackson library to parse json files. I included the library in my gradle script as follows :
...
dependencies {
compile 'org.codehaus.jackson:jackson-core-asl:1.9.0'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.0'
compile 'org.hibernate:hibernate-validator:4.2.0.Final'
testCompile 'junit:junit:4.9'
}
...
I also added my classes folder to classpath.
the build with gradle is ok, it actually downloads the libraries and all, but when I run my program ( from the cmd line with> java name.of.package.Main ) it says :
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/codehaus/jackson/map/JsonMappingException
> at java.lang.Class.getDeclaredMethods0(Native Method)
> at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
> at java.lang.Class.getMethod0(Unknown Source)
> at java.lang.Class.getMethod(Unknown Source)
> at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
> at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException:
> org.codehaus.jackson.map.JsonMappingException
> at java.net.URLClassLoader$1.run(Unknown Source)
> at java.net.URLClassLoader$1.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> ... 6 more
but I noticed that when I add the same two libraries in the gradle file to classpath, everything is ok ..
can someone tell me if I am supposed to add the libraries manually to the classpath ? what’s the use of gradle then in this case ..
thanks a lot!
Gradle doesn’t set the
CLASSPATHenvironment variable (if that’s what you mean). The Application plugin lets you run a command-line application withgradle run. The plugin can also create shell scripts for running the application. In both cases, the correct class path will be passed to the JVM.