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

whitwhoa :

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>

    <groupId>whitwhoa</groupId>
    <artifactId>lwjgl-playground</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <start-class>whitwhoa.Main</start-class>
    </properties>

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

</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?

AK47 :

Pass the -jar parameter as a command line argument:

java -jar lwjgl-playground-1.0-SNAPSHOT.jar

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=106382&siteId=1