У меня есть javafx проект, я сделал jar файл так: в структуре проекта выбрал Artifacts -> нажал плюс -> JAR -> from modules with dependencies . Далее указал где у меня находится Main класс. После этого забилдил jar файл. Нажимаю я на него а там ошибка следующая: Error: Invalid or corrupt jarfile . Как исправить?
Файл manifest.mf
Структура проекта:

1 ответ 1
В общем idea в не правильный каталог генерирует Manifest файл. Нужно его перекинуть в resources
Всё ещё ищете ответ? Посмотрите другие вопросы с метками java javafx или задайте свой вопрос.
Похожие
Для подписки на ленту скопируйте и вставьте эту ссылку в вашу программу для чтения RSS.
дизайн сайта / логотип © 2019 Stack Exchange Inc; пользовательское содержимое попадает под действие лицензии cc by-sa 4.0 с указанием ссылки на источник. rev 2019.11.15.35459
Comments
Copy link Quote reply
ccit-spence commented Apr 13, 2015
I have setup the following Dockerfile. Everything seems to build fine but getting the error that it is corrupt. I did verify that java 8 is set in the POM and manually executed the jar so I know it is working. The other change is that I moved the Dockerfile to the project root. Docker complains about any type of ../ being used to get a path.
Should this work?
This comment has been minimized.
Copy link Quote reply
dsyer commented Apr 13, 2015
It depends on the pom (which you don’t show). Dockerfile ADD works relative to the Dockerfile, so for yours to work you need to copy the jar file to a «target» directory in «target/docker». The maven plugin allows you to do that with a element.
Dan’s technical ramblings
I was creating a Jar via the Java API’s and I couldn’t get it to run my main class:
Running it via the class path worked fine:
So now I knew it was something to do with the manifest file but it wasn’t being caused by
- The 65535 file limit (See Zip64 and Java 7 ).
- The 72 bytes limit per line
- Missing newline at the end of the Main-Class (Displays “no main manifest attribute, in foo.jar”
- A blank line before Main-Class (Displays “Error: An unexpected error occurred while trying to open file foo.jar”
So after scratching my head for a while I tried comparing a working jar with the failing jar:
So don’t prefix the META-INF folder with a slash! Also note it is case sensitive!
3 thoughts on “ Error: Invalid or corrupt jarfile ”
Actually leading slash is forbidden by .ZIP File Format Specification (http://www.pkware.com/documents/casestudies/APPNOTE.TXT). It’s 4.4.17 clause indicate:
The path stored MUST not contain a drive or
device letter, or a leading slash. All slashes
MUST be forward slashes ‘/’ (…).
It’s weird if Java API creates such invalid jars.
Thanks Dan! We had the 65535 jar limit problem and your blog pointed me in the right directions. Ultimately fixed by doing this:
java -jar app.jar
# becomes
java -cp app.jar app.Main
Thank you! Good to know that it could be because of issues with the Manifest.
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.