Can't execute jar- file: “no main manifest attribute”

后端 未结 30 1910
不知归路
不知归路 2020-11-21 22:30

I have installed an application, when I try to run it (it\'s an executable jar) nothing happens. When I run it from the commandline with:

java -jar \

30条回答
  •  醉话见心
    2020-11-21 22:41

    The above answers were only partly helpful for me. java -cp was part of the answer, but I needed more specific info on how to identify the class to run. Here is what worked for me:

    Step 1: find the class I need to run

    jar tf /path/to/myjar.jar | more
    

    The top lines of the result were:

    META-INF/
    META-INF/MANIFEST.MF
    somepath/
    somepath/App.class
    META-INF/maven/
    ...
    

    App.class contained the main class to run. I'm not 100% sure if you can always assume the class you need is the first one, but it was for me. If it isn't, I'd imagine it isn't too hard to use grep to exclude library-related results to pare the class list down to a manageable size.

    From there it was easy: I just use that path (minus the ".class" suffix):

    java -cp /path/to/myjar.jar somepath/App
    

提交回复
热议问题