开发者

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

开发者 https://www.devze.com 2023-02-21 11:02 出处:网络
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.

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 throug开发者_如何学Goh 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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消