I have created a very basic gradle java project that prints "Hello Word". The main class builds and runs fine. When i try to run java -jar out\artifacts\helloWorld_jar\helloWorld.jar
on the command line it gives me this error
Error: Could not find or load main class com.exmple.helloWorld
Caused by: java.lang.ClassNotFoundException: com.exmple.helloWorld
here is how my directory looks
|-gradle
|-.idea
|-build
|-gradle
|-META-INF
|-out
| -artifacts
| -helloWorld_jar
| -helloWorld.jar
|-src
|-main
|-java
|- com.exmple
|-helloWorld
|-test
|build.gradle
etc...
My build.gradle file looks like this:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
jar{
manifest{
attributes "Main-Class": "com.exmple.helloWorld"
}
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
I have tried both single quotes and double quotes and it still runs an error. Any ideas on how to fix this? I have been trying for a few days now.
PS. example is spelt wrong, but its spelt exmple throughout
CodePudding user response:
If the full classname is com.exmpl.helloWorld
, then the source directory structure should be:
|-src
|-main
|-java
|-com
|-exmpl
|-helloWorld.java
not
|-src
|-main
|-java
|-com.exmple
|-helloWorld
Please read What does "Could not find or load main class" mean? for more information. (It explains in depth the many things that can cause this problem.)
CodePudding user response:
It is looking like you have a typo in the path that you are passing:
Error: Could not find or load main class com.exmple.helloWorld Caused by: java.lang.ClassNotFoundException: com.exmple.helloWorld"
An A is missing from example package