Failed to load Main-Class manifest attribute

后端 未结 6 1751
粉色の甜心
粉色の甜心 2021-01-25 16:45

I know this is a very common question, but I tried googling and got no helpful result. I\'m trying to make a jar out of my \"Main.class\" file (made in NetBeans, but I\'m not tr

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-25 17:06

    You can use the -e option of jar to specify the entry point, i.e. the main class. For example:

    D:\NetBeans\trovanum3\build\classes> jar cfe trovanum.jar trovanum3.Main trovanum3\*.class
    

    Saves fiddling with the manifest if that's all you need in there. Note the working directory is one up from that quoted in your question. Otherwise the Main class is created at the top-level in the jar, rather than in a directory that reflects the package in which it should reside. jar -tvf should then show something like this:

      0 Thu Oct 21 22:34:30 BST 2010 META-INF/
     80 Thu Oct 21 22:34:30 BST 2010 META-INF/MANIFEST.MF
    488 Thu Oct 21 22:18:24 BST 2010 trovanum3/Main.class
    

    -e

    Sets entrypoint as the application entry point for stand-alone applications bundled into executable jar file. The use of this option creates or overrides the Main-Class attribute value in the manifest file. This option can be used during creation of jar file or while updating the jar file. This option specifies the application entry point without editing or creating the manifest file.

提交回复
热议问题