0

I just started trying out gradle for java. The documentation for the java plugin says that the default source folder is src/main/java, which to my understanding should be in the following structure:

|-build.gradle
|-src
   |-main
      |-java

This is my groovy code for the build.gradle file.

And this is a picture of my file structure

Why is it that I have to specifically list out the full path including the src/main/java in my jar.mainfile attribute instead of just Backend.Main? Shouldn't gradle automatically assume the source folder portion of the file path?

Edit: as the code is right now, I can build my jar file properly, but when I go to run it, I hit a ClassNotFoundException.

  • *"Why is it that I have to specifically list out the full path including the`src/main/java` in my `jar.mainfile` attribute instead of just `Backend.Main`?"* - Really? What says you have to do that? Where does it say it? – Stephen C Dec 27 '21 at 10:55
  • According to https://stackoverflow.com/questions/21721119, the `mainfile` attribute should be the fully qualified class name; e.g. `Backend.Main` in your case. – Stephen C Dec 27 '21 at 10:58
  • Sorry, I should have made it more clear. I hit an exception when I try to run my jar file, which is why I'm asking. – randomzebra Dec 27 '21 at 11:23
  • You may have jumped to the wrong conclusion. What does the `Main Class` attribute in the JAR's manifest actually contain? What was the complete stacktrace for the exception? – Stephen C Dec 27 '21 at 12:16
  • Ah I got it. My package statement for Main.java included `src/main/java`. – randomzebra Dec 27 '21 at 12:16
  • So ... are you saying that you had a compilation error? (The `package` statement is in the Java source code, and `package src/main/java/Backend.Main;` is invalid Java.) Or are you saying something else. (When you ask a question here it is very important that you say clearly and accurately what you mean. Programming is a **precise** art, and you need to be precise when describing your problem ...) – Stephen C Dec 27 '21 at 12:17
  • That's correct. My full package statement was `package src/main/java/Backend`. The issue was that the gradle build process succeeded, so I thought it was able to compile my code fine. When I went to run my jar file, my code would throw a class not found exception. In any case, the problem was my package statement listing the full file path, which I can see now would cause problems for the builder. – randomzebra Dec 27 '21 at 19:41

0 Answers0