Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run a program contained in a jar file

 
DaDa Zhu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic command is java -jar jarFileName
 
DaDa Zhu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
Jerry Pulley
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic