I\'m trying to run a very simple project using Gradle and running into the following error when using the gradlew run command
:
could not find or l
For a project structure like
project_name/src/main/java/Main_File.class
in the file build.gradle
, add the following line
mainClassName = 'Main_File'
I fixed this by running a clean of by gradle build (or delete the gradle build folder mannually)
This occurs if you move the main class to a new package and the old main class is still referenced in the claspath
Struggled with the same problem for some time. But after creating the directory structure src/main/java and putting the source(from the top of the package), it worked as expected.
The tutorial I tried with. After you execute gradle build
, you will have to be able to find classes
under build
directory.
When I had this error, it was because I didn't have my class in a package. Put your HelloWorld.java
file in a "package" folder. You may have to create a new package folder:
Right click on the hello
folder and select "New" > "Package". Then give it a name (e.g: com.example) and move your HelloWorld.java
class into the package.
Modify build.gradle to put your main class in the manifest:
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version,
'Main-Class': 'hello.helloWorld'
}
}
I see two problems here, one with sourceSet
another with mainClassName
.
Either move java source files to src/main/java
instead of just src
. Or set sourceSet
properly by adding the following to build.gradle.
sourceSets.main.java.srcDirs = ['src']
mainClassName
should be fully qualified class name, not path.
mainClassName = "hello.HelloWorld"