Creating a .jar file - Get “Could not find main class” even with manifest.txt WITH a carriage return

こ雲淡風輕ζ 提交于 2019-12-11 04:49:19

问题


I'm trying to create my first jar file and I'm having trouble. I'm using the DOS to do it and my path and everything are all set up correctly.

These are the files I'm trying to include: Bot.class Start.class Stop.class Thread.class

I've created a manifest file that looks like this (it also has a carriage return at the end)

Main-Class: Bot

Here is what I'm running through the DOS

jar cf Bot.jar Manifest.txt Bot.class Start.class Stop.class Visit.class

It creates the jar successfully and but when I try and execute it, either by clicking on it or using the command prompt I get

Could not find the main class: Bot. Program will exit.

I have tried using both Bot and Bot.class in the manifest file but still get the same error. I've only tried changing the extension on the manifest file to .mf instead of .txt

Thanks in advance for your help!


回答1:


jar cmf Manifest.txt Bot.jar Bot.class Start.class Stop.class Visit.class

The m switch is needed to tell jar which file is the manifest. Note that the order of m and f must match the order of Manifest.txt and bot.jar

Remember that the directory structure in the jar must match your package structure.

e.g. for package com.me.Bot the added file should be com/me/Bot.class not just Bot.class




回答2:


learning how to manually build a jar is a fun thing to do once. for the long term, however, i'd recommend learning a build tool (ant, maven, whatever).



来源:https://stackoverflow.com/questions/5507184/creating-a-jar-file-get-could-not-find-main-class-even-with-manifest-txt-wi

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