This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Executing a jar file from command prompt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Executing a jar file from command prompt" Watch "Executing a jar file from command prompt" New topic
Author

Executing a jar file from command prompt

Sub swamy
Ranch Hand

Joined: Oct 02, 2002
Posts: 121
I would like to execute/run a jar file from command prompt.
I use the command - This raises a "ClassNotFoundException" while trying to connect to a database. I understand that a certain jar file needs to be present in the classpath.

So, i did a set

However, setting this jar file in the classpath doesn't help me out here.
How do i execute this jar file ?
Andrei Matyas
Greenhorn

Joined: Apr 15, 2007
Posts: 25
Hello,

Make sure that the main class is well set in the manifest file (unzip the jar and check MANIFEST.MF).
If no main class is set you should execute it by doing :

java -cp {jarfile} MainClass
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41063
    
  43
Using the CLASSPATH environment variable is notoriously tricky. Try something like

You can also add a classpath entry to the other jar file in the manifest of your jar file. That's probably easiest if both jar files are in the same directory. See http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html#JAR%20Manifest for more detail.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing a jar file from command prompt
 
Similar Threads
Junilu, Ian, Peter and others pls help
where to keep .jar file that is called in jsp page
Executing jar file - Urgent (Max Help)
Setting the classpath
Unable to execute executable jar file