• 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

How to run a program contained in a jar file

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am really fuzzled on how to run a java program, which is contained in a jar file.
I created server.jar based on all classes in my
D:\suncertify\server\
directory. Originally I can run the server like the following:
java -classpath D:\ suncertify.server.DataServer 8189
Now since I have the jar file, I think I do not need these
.class files anymore, so I deleted D:\suncertify\server directory, now how can I run the server using my server.jar?
Thanks,
Zhu
 
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The basic command is java -jar jarFileName
 
DaDa Zhu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me explain my question in detail:
I have db.jar and server.jar, and other jar files, in D:\
I created the server.jar with a manifest file, containing
Main-Class: suncertify.server.DataServer
Now when I run
java -classpath D:\ -jar server.jar 8189
it finds the main() in DataServer well, but this main() calls
Data.class (which is in db.jar), which caused the error:
the jvm can not find Data.class
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DaDa,
Do you have db.jar on the classpath? Try <code>%java -classpath D:\;db.jar -jar server.jar 8189</code>
Jerry
 
DaDa Zhu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jerry, your suggestion works.
Now I have two options:
(1) create one jar file for each package I have, say
db.jar containing suncertify.db;
dbclient.jar containing suncerify.dbclient;
dbserver.jar containing suncertify.dbserver;
client.jar containing suncertify.client
(2) create two jar files:
client.jar containing
suncertify.client, suncerify.dbclient, suncertify.db
server.client containing
suncertify.dbserver, suncertify.db
The advantage of the first option is no redundancy of packages
in different jars, while the advantage of the second option is
it is a little easier to use.
Which way do you use?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic