0

I'm trying to create a jar file with console and run it on windows.

Export.java

public class Export {
    public static void main(String[] args) {
        System.out.println("Hello world :D");
    }
}

then I created the class file Running

C:\Users\inod.jayakody\eclipse-workspace\Program>javac Export.java

added the following manifest.mf file in the same folder containing

MANIFEST.MF

Main-Class: Export

created the jar file in cmd using

C:\Users\inod.jayakody\eclipse-workspace\Program>jar cmvf MANIFEST.MF Inod.jar *.class
added manifest
adding: Export.class(in = 524) (out= 336)(deflated 35%)

but when I'm running the file I'm getting following error am I doing anything wrong? what is the issue here?

C:\Users\inod.jayakody\eclipse-workspace\Program>java -jar Inod.jar
no main manifest attribute, in Inod.jar
Inod Umayanga
  • 114
  • 1
  • 7
  • You don't need manifests anymore for that: ```jar cvfe Inod.jar Export Export.class```. Then ```java -jar Inod.jar``` – g00se Sep 24 '22 at 08:51
  • @g00sereciving this error Error: LinkageError occurred while loading main class Export java.lang.UnsupportedClassVersionError: Export has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 59.0 – Inod Umayanga Sep 24 '22 at 08:57
  • OK. That looks like you have different versions in PATH between java and javac. You need to harmonize them. ```java -version``` ```javac -version``` On Windows, I would set ```JAVA_HOME``` and then, place, *at the start* of ```PATH``` ```%JAVA_HOME%\bin;``` – g00se Sep 24 '22 at 09:01
  • @g00se No I have the same versions: C:\Users\inod.jayakody\eclipse-workspace\Program>**java -version java version "15.0.2"** 2021-01-19 Java(TM) SE Runtime Environment (build 15.0.2+7-27) Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing) C:\Users\inod.jayakody\eclipse-workspace\Program>**javac -version javac 15.0.2** C:\Users\inod.jayakody\eclipse-workspace\Program> – Inod Umayanga Sep 24 '22 at 09:04
  • Strange. You error message is telling you that class was compiled with Java 18. Delete the class file and try again (Obvs. recompile it) – g00se Sep 24 '22 at 09:08
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/248315/discussion-between-g00se-and-inod-umayanga). – g00se Sep 24 '22 at 09:11

0 Answers0