创建.jar文件 - 获取“无法找到主类”即使用manifest.txt WITH回车 [英] Creating a .jar file - Get "Could not find main class" even with manifest.txt WITH a carriage return

查看:230
本文介绍了创建.jar文件 - 获取“无法找到主类”即使用manifest.txt WITH回车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建我的第一个jar文件,我有麻烦。我使用DOS来做它,我的路径和一切都设置正确。



这些是我试图包括的文件:
Bot.class
Start.class
Stop.class
Thread.class



我创建了一个看起来像这样的清单文件(结尾处也有回车符)

 主类:Bot 



这是我通过DOS运行

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

它创建的jar成功,但当我尝试并执行它,无论是通过点击它或使用命令提示符我获得

 找不到主类:Bot。程序将退出。 



我试过在清单文件中使用Bot和Bot.class,但仍然得到相同的错误。我只尝试将清单文件中的扩展名更改为.mf而不是.txt



先感谢您的帮助!

解决方案

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

需要 m jar 哪个文件是清单。请注意, m f 的顺序必须与 Manifest.txt bot.jar



请记住,jar中的目录结构必须与您的包结构。



例如 package com.me.Bot 添加的文件应为 com / me / Bot.class 而不仅仅是 Bot.class


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!

解决方案

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

这篇关于创建.jar文件 - 获取“无法找到主类”即使用manifest.txt WITH回车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆