• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

executable jar file

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I'm new to java and I'm trying to make an executable jar file with no luck so far. My OS is windows xp.

I have my compiled class file: GuiDemo.class located at C:\Java Projects\bin\com\test\common. I created a manifest file: GuiDemo.mf at the same location which has the below contents and a blank line at the end of the manifest file.

Manifest-Version: 1.0
Main-Class: com.test.common.GuiDemo

I created the executable jar file like below at command prompt:

C:\Java Projects\bin\com\test\common>jar cmf GuiDemo.mf GuiDemo.jar GuiDemo.class

The above command did create an executable jar file: GuiDemo.jar, which I tested using C:\Java Projects\bin\com\test\common>jar -tf GuiDemo.jar and it gave the following result.

META-INF/
META-INF/MANIFEST.MF
GuiDemo.class

But, when I try to execute the jar file using: C:\Java Projects\bin\com\test\common>java -jar GuiDemo.jar, it is giving NoClassDefFound exception and the last line says: Could not find the main class: com.test.common.GuiDemo.class. Program will exit.

My CLASSPATH is set as C:\Java Projects\bin. I can execute GuiDemo without any issues using C:\>java com.test.common.GuiDemo

What could be wrong?



 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The classes inside your JAR file must be placed in a directory structure that matches the package declarations. In this case, your JAR file must contain a folder com\test\common and the GuiDemo.class file must be placed inside that folder.
 
Philip Mat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thank you for that information. How can I include a folder structure in a jar file?

Can you show me an example?
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/docs/books/tutorial/deployment/jar/index.html
The input files do not necessarily need to be files - they can be folders as well.
 
Philip Mat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks .. It worked ..
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic