Tag Archives: Ubuntu Error

Ubuntu Error: Invalid or corrupt jarfile xxx.jar [How to Solve]

1. Problem description

After packaging Maven project into jar package in Ubuntu environment, run the following instructions:

1 $ java -jar my.jar

An error occurred:

1 Error: Invalid or corrupt jarfile my.jar

2. Problem analysis

First, make sure that the jar package is not damaged during transmission

If the jar package is not damaged, it is most likely that the entry information is misconfigured or lost

3. Solutions

Case 1: the configuration of information in manifest.mf file in meta-inf folder in Java directory is wrong

Open the manifest.mf file and observe whether the main function entry corresponding to main class: is correct, for example:

1 Manifest-Version: 1.0
2 Main-Class: com.myproject.Main

Case 2: the information in manifest.mf file is configured correctly, but the program entry cannot be found correctly

In this case, the entry information may be lost in the packaging process, there are too many entries, the main entry is not specified, or the entry cannot be successfully found for other reasons. You can use the – CP instruction to forcibly specify the program entry. The instruction is as follows:

1 $ java -cp my.jar com.myproject.Main

After finding the entry, the program can run smoothly