Error: Could not find or load main class - .jar file execution

I've been digging and digging trying everything I can to resolve this but nothing seems to be working. I just installed Intellij IDEA on my machine and created a new maven project. I am simply attempting to execute a hello world program to verify everything is setup correctly. However, something is not right.

When running the application in IDEA I receive "Hello World" as expected. However when running maven package and generating a .jar file, when I attempt to execute that .jar file I receive the following message:

C:\dev\lwjglplayground\target>java lwjgl-playground-1.0-SNAPSHOT.jar
Error: Could not find or load main class lwjgl-playground-1.0-SNAPSHOT.jar
Caused by: java.lang.ClassNotFoundException: lwjgl-playground-1.0-SNAPSHOT.jar

My first instinct was that I had botched something in my java installation (as right before installing IDEA I removed my java 8 jdk and installed jdk 11), but I verified that other .jar files which I had previously built execute as expected.

My pom.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
&lt;groupId&gt;whitwhoa&lt;/groupId&gt;
&lt;artifactId&gt;lwjgl-playground&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;packaging&gt;jar&lt;/packaging&gt;

&lt;properties&gt;
    &lt;start-class&gt;whitwhoa.Main&lt;/start-class&gt;
&lt;/properties&gt;

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.8.0&lt;/version&gt;
            &lt;configuration&gt;
                &lt;release&gt;11&lt;/release&gt;
                &lt;archive&gt;
                    &lt;index&gt;true&lt;/index&gt;
                    &lt;manifest&gt;
                        &lt;mainClass&gt;whitwhoa.Main&lt;/mainClass&gt;
                    &lt;/manifest&gt;
                &lt;/archive&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.1.1&lt;/version&gt;
            &lt;configuration&gt;
                &lt;archive&gt;
                    &lt;index&gt;true&lt;/index&gt;
                    &lt;manifest&gt;
                        &lt;mainClass&gt;whitwhoa.Main&lt;/mainClass&gt;
                    &lt;/manifest&gt;
                &lt;/archive&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

</project>

This is my Main.java file:

package whitwhoa;

public class Main {

public static void main(String[] args) {
    System.out.println("Hello World");
}

}

Does anything here stick out to anyone as being misconfigured? Am I missing something?

#java #maven

3 Likes3.90 GEEK