• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing a jar file from command prompt

 
Sub swamy
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic