简体   繁体   English

Java jar运行

[英]Java jar running

Any idea why 知道为什么

java -jar jarname.jar

works, but double clicking the jar gives a 可以,但是双击罐子

"Could not find the main class:"

error? 错误? Manifest is correctly placed and double clicking was working until recently, but all of a sudden it gives that error. 清单已正确放置,并且双击一直有效直到最近,但是突然之间出现了该错误。 I'm not sure what changes I made though. 我不确定我做了什么更改。

EDIT: 编辑:
The command I used to create the jar was (in cmd): 我用来创建jar的命令是(以cmd为单位):

jar cfe jarname.jar files.Main *

Main is part of the package files. Main是软件包文件的一部分。

Add this entry in your manifest file: 将此条目添加到清单文件中:

Main-Class: com.abc.def.YourMainClass

Hope this'll help! 希望这会有所帮助!

Some time ago I had a comparable problem. 前段时间我遇到了类似的问题。 And it was caused by multiple JDK/JRE versions on my machine. 这是由我的机器上的多个JDK / JRE版本引起的。 What is used by double-clicking differs from what is used by typing jar in a shell. 双击所使用的内容与在外壳中键入jar所使用的内容不同。

I think JarFix could help. 我认为JarFix可以提供帮助。 Or you lookup what is associated with double-click in the file-associations (reinstall java might also help) 或者您在文件关联中查找与双击关联的内容(重新安装java可能也有帮助)

It seems to have been some weird compiler version problem. 看来这是一些奇怪的编译器版本问题。 When I complied the class files using an older version of java, then compiled it into a .jar file, it was able to run. 当我使用较旧版本的Java编译类文件,然后将其编译为.jar文件时,它便能够运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM