• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating an executable JAR  RSS feed

Graeme Byers
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • 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
Campbell Ritchie
Posts: 56578
  • Mark post as helpful
  • send pies
  • 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.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!