Monday, May 15, 2023
HomeSoftware EngineeringEasy methods to Make a Java Jar File Executable

Easy methods to Make a Java Jar File Executable

Let’s say you might have a Java venture as follows:

package deal thing;
public class MyProject {
    public static void major(String...args) throws Exception {
        System.out.println("Hey world!");

Now you wish to construct this and make it a self contained executable Jar.

Should you do a mvn clear set up or mvn clear package deal, and attempt to run it as follows:

java -jar goal/my-java-1.0-SNAPSHOT.jar

You’ll get the next error:

no major manifest attribute, in goal/my-java-1.0-SNAPSHOT.jar

Easy methods to Remedy no major manifest attribute error

You’ll be able to remedy this error by including the next in your pom.xml file:

                        <mainClass> thing.MyProject</mainClass>

Now construct your answer like this:

mvn clear set up package deal

Then run your standalone Jar as follows:

java -jar goal/my-java-1.0-SNAPSHOT.jar


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments