0

I follow this starter tutorial.

I can not run the code with this command :

$ java -cp gs-gradle-0.1.0.jar hello.HelloWorld

I have this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/joda/time/LocalTime
    at hello.HelloWorld.main(HelloWorld.java:11)
Caused by: java.lang.ClassNotFoundException: org.joda.time.LocalTime
        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)
        ... 1 more

All import classes are not found. But with gradle command it works :

$ ./gradlew run

Why with java command, it doesn't work ?

Thanks

4
  • 1
    It appears the issue is that JodaTime isn't on your runtime classpath. Commented Dec 11, 2017 at 21:21
  • The point of the application plugin is to generate a zip or tar file containing everything you need to run the app, including startup scripts that set up the right classpath and run the application. You should use them. Commented Dec 11, 2017 at 21:27
  • So i must download all jar files that I import in my class ? And put them in /libs ? Commented Dec 11, 2017 at 21:31
  • No. You need to use the startup scripts generated by the build. Please read docs.gradle.org/current/userguide/application_plugin.html Commented Dec 11, 2017 at 21:41

1 Answer 1

1

Of course it does not work, the Tutorial also told you so.

The application plugin adds the run task (and other tasks) that put your dependency on the classpath.

If you use the distZip or distTar task you get an archive with all your dependencies and with start scripts that set the correct classpath that you can use to run your application.

Read more about the application plugin at https://docs.gradle.org/current/userguide/application_plugin.html.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.