Issue
I know this question has been asked a lot but non of the answers worked for me.
I keep getting "Error: Could not find or load main class app.Main.java" when trying to run my jar (created with maven).
CMD command:
java -jar .\RideShare-1.0-SNAPSHOT.jar
pom.xml
:
<?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>org.example</groupId>
<artifactId>RideShare</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- <classpathPrefix>libs/</classpathPrefix>-->
<mainClass>app.Main.java</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
.
.
.
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>
and this is a screenshot of my project's structure:
What am I missing?
Solution
as @slindenau mentioned in his comment, the problem was that I used the wrong class name format in <mainClass>...</mainClass>
.
To get the fully qualified name (using IntelliJ), I did:
right-click
on the class name -> "Copy Path/Reference"
-> "Path From Source Root"
.
and that gave me "app/Main.java" while what I needed was "app/Main".
So finally,
<mainClass>app.Main</mainClass>
worked for me.
Answered By - Kfir Ettinger
Answer Checked By - Marilyn (JavaFixing Volunteer)