• 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

Creating an executable JAR

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to create an executable JAR from Message.class and Hello.class both in C:\GBJAVA\ClassLib\English\com\hotmail.graemebyers
Here is the source :


The manifest C:\Manifest.txt contains this line :
Main-Class: com.hotmail.graemebyers.Message

It seems that to do this the directory containing the .class(s) must be made the current directory as indicated by . (dot)
C:\GBJAVA\ClassLib\English>jar cvmf C:\Manifest.txt C:\Message.jar .

C:\GBJAVA\ClassLib\English>java -jar c:\Message.jar // OK : prints Message , Hello

C:\GBJAVA\ClassLib\English>jar -tvf c:\Message.jar // Looks OK


BUT if I include the class directory then it is included in the jar :

C:\GBJAVA\ClassLib\English>jar cvmf c:\Manifest.txt c:\Message.jar C:\GBJAVA\ClassLib\English
C:\GBJAVA\ClassLib\English>java -jar c:\Message.jar // NoClassDefFoundError : com/hotmail/graemebyers/Message
C:\GBJAVA\ClassLib\English>jar -tvf c:\Message.jar


If I rename c:\JAVA to c:\JAVAXXX then jar -xf extract will recreate the appropriate directories - OK.

FINALLY - my questions :
1. Should I put directory info in a jar ?
2. How do I execute a jar if I put directory info in it ?
3. What do real-life "production" JARs contain ?

Nice work on the site
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You should be able to get simple .jars to execute by writing the name of the class with the main method in their manifest file. I presume you have been through the Java Tutorials?

By the way: are you actually allowed to use com.hotmail as a package name? There are conventions about package names.
reply
    Bookmark Topic Watch Topic
  • New Topic