saha saha - 5 months ago 143
Java Question

Maven Error: Could not find or load main class MLSH-0.0.1-SNAPSHOT.Jar

I used Maven to make dependency and build jar file for my project. I generated the Jar file successfully, but I encountered the following problem:

Error: Could not find or load main class MLSH-0.0.1-SNAPSHOT.Jar


I used the following plugins in my POM file:

POM.XML



<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>metric_Learning.Variable_Initialization</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>


What you recommend me to solve the error?

Answer

In the configuration of the plugin, you need to specify the main class to be added to the manifest, as described here to make the generated JAR file executable.

<configuration>
    <!-- ... -->
    <archive>
        <manifest>
            <mainClass>com.whatever.Main</mainClass>
        </manifest>
    </archive>
    <!-- ... -->
</configuration>

Also, (unless you changed the default naming of the JAR file containing the dependencies), you need to execute the one that ends with ...-with-dependencies.jar