Error: Could not find or load main class HelloWorld

Ok, managed to set the main class attribute in the manifest for the JAR, but the JAR doesn’t seem to contain the .class file:

`
thufir@mordor:~/java$
thufir@mordor:~/java$
thufir@mordor:~/java$ gradle clean
:clean UP-TO-DATE

BUILD SUCCESSFUL

Total time: 5.278 secs
thufir@mordor:~/java$
thufir@mordor:~/java$ gradle build
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 5.086 secs
thufir@mordor:~/java$
thufir@mordor:~/java$ gradle assemble
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE

BUILD SUCCESSFUL

Total time: 5.067 secs
thufir@mordor:~/java$
thufir@mordor:~/java$ java -jar build/
libs/ tmp/
thufir@mordor:~/java$ java -jar build/libs/java-0.5.jar
Error: Could not find or load main class HelloWorld
thufir@mordor:~/java$
thufir@mordor:~/java$ jar -tf build/libs/java-0.5.jar
META-INF/
META-INF/MANIFEST.MF
thufir@mordor:~/java$
thufir@mordor:~/java$ cat build.gradle
apply plugin: ‘java’

version = “0.5”

jar
{
manifest.attributes(“Main-Class”: “HelloWorld”)
}

task hello << {
println ‘hello, world’
}

thufir@mordor:~/java$
thufir@mordor:~/java$ ll src/
total 20
drwxrwxr-x 2 thufir thufir 4096 Jan 30 05:06 ./
drwxrwxr-x 5 thufir thufir 4096 Jan 31 03:43 …/
-rw-rw-r-- 1 thufir thufir 123 Jan 30 04:47 HelloWorld.java
thufir@mordor:~/java$
thufir@mordor:~/java$ cat src/HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println(“Hello World!”);
}
}
thufir@mordor:~/java$

`

By convention the Java plugin only compiles sources files under src/main/java. You can reconfigure the plugin to search for source files under src instead. I’d recommend you read the user guide on the Java plugin.

thanks for the help :slight_smile:

I am using below code, I am getting same issue like you. Did you got the resolution?

duplicatesStrategy=‘include’
manifest {

    attributes 'Implementation-Title': 'Gradle Jar File Example',  
    	'Implementation-Version': project.version,
    	  	'Main-Class': 'com.mortgageApi.util.EmailTestReport'        	
}
baseName = "$project.name-all"  

from {project.configurations.runtimeClasspath.collect {File file → project.zipTree(file) } }
}