GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes executable Jars  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "executable Jars  " Watch "executable Jars  " New topic
Author

executable Jars

Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Ok this is driving me nuts I keep on getting "failed to load Main-Class attribute from Viewer.jar"

I have a typical package directory set up com.yadda.something.else and com.another.something and then I have another.jar

I run jar -cmf Viewer.mf Viewer.jar *.*

and inside Viewer.mf I have:
Class-Path: Viewer.jar
Main-Class: com.yadda.something.else.View

I've also tried chaning main-class to: com/yadda/something/else/View

Both times I get the same error.

Anyone know what I'm doing wrong?

-Tad
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Ok I guess a good starting point would be...

Whats the difference between "Failed to load Main-Class manifest attribute from C:\jartest\Viewer.jar"

and

Could not find the main class. Program will exit

?

is one error closer to the "right path" than the other?
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Ok I tried removing the reference to the external jar and it works fine.

I would like to use the plastic3DLookAndFeel from JGoodies, but I don't know how to include it in the jar. I was just keeping the jar in the directory that I was creating my jar in. it was getting included but for some reason I still can't call the classes in it from my class.

-Tad
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Ok well I got around the problem by unpacking the external jar and adding it to the package structure I was putting into the jar.

Still I think it would be nice if instead of saying couldn't find main class it would tell you what exception was being thrown.

-Tad
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

You seem to have come to a solution on your own, but did you try changing the order of the attributes -- first Main-Class, and then Class-Path?


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Yes, I tried playing around with the order. I'm not sure it mattered much. I guess I just don't fully grasp how to specify the proper classpath so that jars inside of jars are accessed properly or how to get classes inside of the jar to properly reference/use classes inside of external jars.

-Tad

PS I guess the thing that irritated me the most was the cryptic error messages recieved when trying to run the jar. They didn't do much to help pinpoint the issue. And the code causing the problem was:
[code]
try
{
javax.swing.UIManager.setLookAndFeel(new com.jgoodies.plaf.plastic.Plastic3DLookAndFeel());
}
catch(Exception e ){}
[code]

I would think that if it couldn't find the class it would merely throw an exception and startup anyways using the default look and feel. Instead it threw an error saying it couldn't load the main class.

Seems counter intuitive to me.
[ March 18, 2005: Message edited by: Tad Dicks ]
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I think you are miss-interpreting the error message. If I read you right you tried:
jar -cmf ...
which would be the command to create a jar file, not run one.

java -jar would be the command to run a jar file.

The Main-Class attribute does have to come before the Class-Path attribute in the manifest file. Also there must be an empty line after the Class-Path attribute.
 
GeeCON Prague 2014
 
subject: executable Jars