Cannot run Java application. Main not found [duplicate]

Deadly 提交于 2020-02-06 17:44:46

问题


I am completely new to java and I need to just run an application I downloaded off the internet. The application in question is the "spinn3r" client found here: http://code.google.com/p/spinn3r-client/downloads/detail?name=spinn3r-client-3.4.06.tar.gz

I extracted the tar.gz and found a .jar file. I then ran:

java -jar applicationName.jar

I get the following error:

no main manifest attribute, in spinn3r-client-3.4.06.jar

How do I fix this?


回答1:


As @Alderath mentioned, this is primarily an API which you can use in your own applications. Nevertheless, the jar file also contains a test client which you can launch as follows:

$ java -cp spinn3r-client-3.4.06.jar com.spinn3r.api.Main
Usage: com.spinn3r.api.Main [OPTION]

Required params:
...

Since this it is not an executable jar file, you need to pass the required jar files and the class which contains the main method explicitly.




回答2:


For a JAR file to become executable, under META-INF/MANIFEST.MF, in your jar, you need to have this attribute:

Main-Class: youclassname.class



回答3:


Collect all your .java files and .class files (and anything else you want to include) together in a single directory. Using a text editor, create a file (say, myManifest) containing the following lines:

      Manifest-Version: 1.0
      Main-Class: MyMainClass

where MyMainClass is the name of the class containing the main method you want to use.
From the command line, execute the command:

     jar cvfm myResult.jar myManifest *.java *.class

where myResult.jar is the jar file you are trying to create, myManifest is the file you created in step 2, and everything else is the files you want to include.


来源:https://stackoverflow.com/questions/15156562/cannot-run-java-application-main-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!