• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

noobie jar file creation missing main class problem  RSS feed

 
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry - I feel like I should be able to work this out myself, but I've tried googling and haven't been able to find anything that works for me.

I've got a multi-file app with sources all under src/stf; they all start with 'package stf;'. Its main() is in class MainFrame (in src/stf/MainFrame.java).

So my (linux) jar command line is:
That seems to execute ok, but when I try to run the generated file:
I get:
I've tried specifying the entry point as MainFrame rather than stf.MainFrame but that doesn't help.

What am I doing wrong?

Cheers
John
 
Rancher
Posts: 3306
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look inside the jar file to see what's there. An easy way is to use a zip file utility by renaming the jar file by adding the zip extension.
See if the stf folder contains the MainFrame.class file.   The stf folder should be at the top/root level.
Also look in the manifest file to see what it contains.
 
John Matthews
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Norm

Norm Radder wrote:Look inside the jar file to see what's there. An easy way is to use a zip file utility by renaming the jar file by adding the zip extension.

'jar tf MainFrame.jar' seems to work, and the output includes:

See if the stf folder contains the MainFrame.class file.

Yep. (I should have said that I can run the app by using 'java stf.MainFrame'.)

The stf folder should be at the top/root level.

Sorry - not sure what you mean.

Also look in the manifest file to see what it contains.


How do I generate that?
 
Marshal
Posts: 61690
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The manifest is an essential part of a .jar file; in fact the only difference from an ordinary .zip file is the existence of the manifest file. I think it would be a good idea to go through the Java™ Tutorials, which will probably answer all your questions.
 
John Matthews
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:The manifest is an essential part of a .jar file


Thanks Campbell, but I've read that it is optional?

One of the things I did try earlier though was to create a one line manifest just to specify the main class. Again, jar didn't complain, but I got the same message when I tried to execute the generated .jar.
 
John Matthews
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've read a bit more, and if I use the following jar command line:
then use the following to extract the files from the generated .jar:
then the extracted generated default manifest in META-INF/MANIFEST.MF only contains (in addition to the version and created-by):
But using jar tf shows that the .jar contains all the expected .class files.

I'll keep reading...
 
Campbell Ritchie
Marshal
Posts: 61690
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Matthews wrote:

Campbell Ritchie wrote:The manifest is an essential part of a .jar file


Thanks Campbell, but I've read that it is optional? . . ..

Where on earth did you see that? The jar tool will create the manifest file for you unless you prohibit it. You need to specify the class with the main method in the manifest file. The link I gave you should answer just about all your questions. Remember to use the enter key at the very end of the manifest file.
 
John Matthews
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant that the manifest is optional as an input to the jar tool, and that's true, isn't it? And I'm using the jar tool's e option to specify the class containing the entry point, which seems to be working in as much as the argument appears on the Main-Class line of the generated manifest.
 
Norm Radder
Rancher
Posts: 3306
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the output includes:
src/stf/MainFrame.class


If that is the contents of the jar file then it shows the src folder is at the top/root level.  The stf folder needs to be at the top level because it is the package the class is in.
Change the use of the jar command to have the stf folder be the top/root level folder.  Get rid of putting the src folder in the jar file.
 
John Matthews
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Norm - that sort of makes sense, and results in an executable .jar file. Basically I run the jar command in the src directory instead of above it, and that seems to do the trick.
 
John Matthews
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is, I go into the src directory and enter:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!