Я не могу открыть файл .jar в Ubuntu 18.04.4

я новичок в Linux и хочу помочь с приложениями Java. У меня есть несколько файлов .jar, которые я импортировал с другого мобильного устройства. Я установил пакет default-jre из apt . Когда я запускаю java -jar app.jar , я получаю сообщение об отсутствии основного атрибута манифеста . Пожалуйста, помогите.

PS: Я не являюсь владельцем пакетов и ничего не знаю о программировании на Java.

0
задан 25 July 2020 в 13:10

1 ответ

The jar file must have MANIFEST file in it which tells the compiler which class has the main method. Since this file/information is missing in the jar file, you need to know the fully qualified name of this class, e.g.

java -cp app.jar com.somepackage.SomeClass

We can find this special class even if we do not have the source files. e.g. Download a helloworld file without the main manifest attribute from java2s.com.

mkdir hello && mv helloworld-2.2.jar.zip hello
unzip helloworld-2.2.jar.zip
unzip helloworld-2-2.jar
grep -nr main .

This' output

Binary file ./org/glassfish/jersey/examples/helloworld/App.class matches

Here we know which file contains the main method. To get the "Fully Qualified Class Name", we replace '/'s with '.'s. Now we have two options

  1. We pass the class name to java command.

    java -cp helloworld-2.2.jar org.glassfish.jersey.examples.helloworld.App

  2. Install default-jdk, and update the jar manifest file with this class name

jar -uvfe helloworld-2.2.jar org.glassfish.jersey.examples.helloworld.App
java -jar helloworld-2.2.jar 
1
ответ дан 30 July 2020 в 22:02

Другие вопросы по тегам:

Похожие вопросы: