Help with manifest.txt for .jar

I have two class files I'm trying to create a .jar file for:

InventoryMain.class (houses my main)

Inventory.class

Both files are in package inventorymain

Here is everything I have tried in my manifest.txt file:

Manifest-Version: 1.0

Main-Class: inventorymain.InventoryMain (1st try)

Main-Class: InventoryMain (2nd try)

Main-Class: inventorymain (third try)

I use the following in command prompt:

jar cvfm Inventory.jar manifest.txt *.class (this runs and says all 3 files are included)

then when I try to run Inventory.jar I get the following error:

A window pops up labeled Java Virtual Machine Launcher with the error of "could not find the main class. Program will exit.

Anyone know what I am doing wrong? I am a student, and this is the first program I have created that uses more than one file. I have been all over the Internet to look for things I can do. I am stumped!! Anyhelp would be appreciated. Here is the beginning of my main program, if it will help someone help me.

package inventorymain;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.BufferedReader;

publicclass InventoryMain

{

// Creates a new instance of InventoryMain

public InventoryMain()

{

}

// main method begins execution of java application

publicstaticvoid main(String[] args)

{

[1955 byte] By [javahelp44a] at [2007-11-27 7:34:56]
# 1

Your 1st attempt was correct. (inventorymain.InventoryMain)

It is likely that your class files are not in the correct directories. The directory structure in the jar files has to match the directory structure that would exist if you were working with loose class files.

You indicate that InventoryMain is in the package inventorymain.

Assuming that your class files are in a directory called "inventorymain",

cd up one directory and recreate the jar file.

jar cvfm Inventory.jar inventorymain/manifest.txt inventorymain/*.class

The class files are in inventorymain aren't they? ... they are supposed to be.

If they are not, and you don't understand why they should be, you should take a look at the info on packages.

http://java.sun.com/docs/books/tutorial/java/package/index.html

found a url for some package info

Message was edited by:

johndjr

johndjra at 2007-7-12 19:15:27 > top of Java-index,Java Essentials,New To Java...
# 2

Hi johndjr:

Yes I do have them all in a directory called inventorymain

I have tried the same line you have advised me to try and everything is fine up to the point of when I run my program. I type in Inventory.jar at the command prompt, and absolutely nothing happens.

C:\****>Inventory.jar

C:\****>

That is what I get... no error, no program executing... nothing! Anymore ideas I can try?

javahelp44a at 2007-7-12 19:15:27 > top of Java-index,Java Essentials,New To Java...
# 3
At the command prompt, type:java -jar yourfile.jar
Hippolytea at 2007-7-12 19:15:27 > top of Java-index,Java Essentials,New To Java...
# 4
Still absolutely nothing happens....C:\****>java -jar Inventory.jarC:\****>
javahelp44a at 2007-7-12 19:15:27 > top of Java-index,Java Essentials,New To Java...
# 5
What *should* happen?
Hippolytea at 2007-7-12 19:15:27 > top of Java-index,Java Essentials,New To Java...
# 6
it is an inventory program that displays product name, product number, unit price, and value of products in inventory.This program works perfectly when I have it open in netbeans and run it from there.Any suggestions?
javahelp44a at 2007-7-12 19:15:27 > top of Java-index,Java Essentials,New To Java...
# 7

Here is both of my .java files

package inventorymain;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.BufferedReader;

public class InventoryMain

{

// Creates a new instance of InventoryMain

public InventoryMain()

{

}

// main method begins execution of java application

public static void main(String[] args)

{

//create inventory of pens

Inventory pens = new Inventory(); //creating the inventory with empty constructor

pens.setItemNum( 1 );

pens.setName( "pens" );

pens.setPrice( 1.59 );

pens.setUnits( 346 );

//create inventory of pencils

Inventory pencils = new Inventory(); //creating the inventory with empty constructor

pencils.setItemNum( 2 );

pencils.setName( "pencils" );

pencils.setPrice( .59 );

pencils.setUnits( 487 );

//create inventory of markers

Inventory markers = new Inventory(); //creating the inventory with empty constructor

markers.setItemNum( 3 );

markers.setName( "markers" );

markers.setPrice( 1.29 );

markers.setUnits( 168 );

//create inventory of paperclips

Inventory paperclips = new Inventory(); //creating the inventory with empty constructor

paperclips.setItemNum( 4 );

paperclips.setName( "paperclips" );

paperclips.setPrice( 1.19 );

paperclips.setUnits( 136 );

//create inventory of glue

Inventory glue = new Inventory(); //creating the inventory with empty constructor

glue.setItemNum( 5 );

glue.setName( "glue" );

glue.setPrice( .79 );

glue.setUnits( 72 );

//create inventory of tape

Inventory tape = new Inventory(); //creating the inventory with empty constructor

tape.setItemNum( 6 );

tape.setName( "tape" );

tape.setPrice( .49 );

tape.setUnits( 127 );

//create inventory of paper

Inventory paper = new Inventory(); //creating the inventory with empty constructor

paper.setItemNum( 7 );

paper.setName( "paper" );

paper.setPrice( 1.79 );

paper.setUnits( 203 );

//Display the inventories

pens.showInventory();

System.out.println(); //enters blank line

System.out.println(); //enters blank line

pencils.showInventory();

System.out.println(); //enters blank line

System.out.println(); //enters blank line

markers.showInventory();

System.out.println(); //enters blank line

System.out.println(); //enters blank line

paperclips.showInventory();

System.out.println(); //enters blank line

System.out.println(); //enters blank line

glue.showInventory();

System.out.println(); //enters blank line

System.out.println(); //enters blank line

tape.showInventory();

System.out.println(); //enters blank line

System.out.println(); //enters blank line

paper.showInventory();

}//end Main

}//end class InventoryMain

package inventorymain;

public class Inventory

{

private int itemNum;

private String name = new String();

private int units;

private double price;

//All getters and setters

public int getItemNum()

{

return itemNum;

}

public void setItemNum(int itemNum)

{

this.itemNum = itemNum;

}

public String getName()

{

return name;

}

public void setName(String name)

{

this.name = name;

}

public int getUnits()

{

return units;

}

public void setUnits(int units)

{

this.units = units;

}

public double getPrice()

{

return price;

}

public void setPrice(double price)

{

this.price = price;

}

//Constructors

Inventory() // Empty Constructor

{

}

//Constructor that takes arguments

Inventory(int _itemNum, String _name, int _units, double _price)//Constructor

{

itemNum = _itemNum;

name = _name;

units = _units;

price = _price;

}

//Computes value of inventory

public double valueOfInventory()

{

return price * units;

}

//displays the details of the inventory

public void showInventory()

{

System.out.println("Product Name: "+name);

System.out.println("Item Number: "+itemNum);

System.out.println("Number of Units: "+units);

System.out.println("Unit Price: $"+price);

//call the valueOfInventory() method and display the value

System.out.println("The value of " +name+ " left in the inventory is: $"+valueOfInventory());

}

}// end class Inventory

javahelp44a at 2007-7-12 19:15:27 > top of Java-index,Java Essentials,New To Java...
# 8

This might sound a bit strange, but are you sure that you jarred the same class files that netbeans was running?

Perhaps you had an older version that did not print anything?

I just tried the source you posted and it seemed to work.

I don't see any reason why it shouldn't work for you.

You shouldn't get silence.

If you still have the class files you used to create the jar, try

doing the following and see if program does the correct thing.

cd to the directory where inventorymain is

java -cp .\ inventorymain.InventoryMain

For a program as simple as this there shouldn't be too much that can go wrong when making an executable jar file.

johndjra at 2007-7-12 19:15:27 > top of Java-index,Java Essentials,New To Java...
# 9
Make sure the last line of manifest.txt ends with a NewLine.In other words, if you move the cursor to the end of the file in an editor,it goes at the begining of the line following the line:Main-Class: inventorymain.InventoryMainMessage was edited by:
baftosa at 2007-7-12 19:15:27 > top of Java-index,Java Essentials,New To Java...