how to include a an external jar file in a class path to to compile and run a java program?

Posted on 2007-04-05
Medium Priority
Last Modified: 2013-11-23
how to include a an external jar file in a class path to to compile and run a java program? what is the command line instruction?
Question by:anup001
  • 4
LVL 30

Expert Comment

by:Mayank S
ID: 18860873
java - cp. yourJARFilePath yourMainClassName
LVL 30

Accepted Solution

Mayank S earned 2000 total points
ID: 18860895
There are various options, like adding it to the classpath environment variable, putting the JAR to your JRE\lib\ext, or specifying it as a command line switch option. See a classpath explanation here:


(And on the link posted at the end of that comment: http://www.mindprod.com/jgloss/classpath.html)

The switch option is also explained in detail here:


and here: http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.html

Author Comment

ID: 18860973
All these instructions are for java command. I need info for the javac.
LVL 30

Expert Comment

by:Mayank S
ID: 18860985
You said compile and run. I gave it for run. The links contain the same for the compile command as well:

javac -classpath JARFilePath YourFileName.java

Also explained in detail: http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html
LVL 30

Expert Comment

by:Mayank S
ID: 18861126
>> java - cp. yourJARFilePath yourMainClassName

The . will not be there.... it came by mistake

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question