aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to run a program contained in a jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to run a program contained in a jar file" Watch "How to run a program contained in a jar file" New topic
Author

How to run a program contained in a jar file

DaDa Zhu
Greenhorn

Joined: Jan 07, 2001
Posts: 11
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

Joined: Oct 02, 2000
Posts: 688
The basic command is java -jar jarFileName
DaDa Zhu
Greenhorn

Joined: Jan 07, 2001
Posts: 11
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

Joined: Sep 19, 2000
Posts: 221
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

Joined: Jan 07, 2001
Posts: 11
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to run a program contained in a jar file
 
Similar Threads
executalbe jar file problem
classpath problem
Problem running jar
strange case with jar tool
Passed With 141/155 (~91%)