0

I'm going through the lesson of creating my first program on Java and using a gradle to compile and build.

Here is the code of the program

class HelloGradle{
public static void main(String[] args) {
System.out.println("Hello, world!");
}}

I put my file into src->main->java->HelloGradle.java

Then I created build.gradle file with such parameters inside apply plugin: 'java'

When I try to build using gradle build it's says that BUILD success-full and create build folder So I add such lines to build.gradle file

apply plugin: 'application'
mainClassName = "HelloGradle"

Then I try to run it from a root folder with such command gradle run. But build is got failed. Here is the log of an error

Task :run FAILED
Task ':run' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Starting process 'command '/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java''.
     Working directory: /Users/dmytro/Desktop/java/sandbox
     Command: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java
     -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant
     -cp /Users/dmytro/Desktop/java/sandbox/build/classes/java/main:/Users/dmytro/Desktop/java/sandbox/build/resources/main
     HelloGradle
Successfully started process 'command '/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java''
Error: Could not find or load main class HelloGradle
Caused by: java.lang.ClassNotFoundException: HelloGradle``

So it seems like gradle not able to find class file even though that I specified it in configuration file. What is my next step to find a solution. Thanks a lot

Gray
  • 115,027
  • 24
  • 293
  • 354

1 Answers1

0

Wow I just started a course to learn Java and typed exactly as it was on video but there was no explanation what is public and that is why gradle was not able to find it.

But as soon as I add in a code. It was successfully build and run ok in terminal. Thanks everyone . Lesson learned

  • What does "add in a code" mean? Can you be more explicit so that others can learn from you? Maybe show the config lines that were missing? – Gray Jul 09 '18 at 13:25