Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Creating an executable JAR  RSS feed

 
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
 
Marshal
Posts: 60199
188
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!