Sandeepan Nath
Sandeepan Nath

Reputation: 10294

How to add/reference .jar files in your project when you don't have an IDE

I am new to Java (basically a LAMP developer). I got this JAVA API to parse .pst files and show all the inbox messages.

I tried executing a given .class file but it throws exceptions. I need to add/reference some .jar files provided by the API.

I don't have any IDE for Java yet. Wikihow says

When your Java project requires JAR libraries to function, you have to configure your project to include the libraries in its build path. Fortunately, Eclipse makes this process simple and easy to remember. The build used here is Eclipse Java - Ganymede 3.4.0.

So, what configuration do I have to do? Or is it better to get Eclipse IDE? I just have a single .class file to be executed.

A few other questions that I checked but could not get my answer - How to add external jar libraries to an android project from the command line

How do I include external JARs in my own Project JAR

Upvotes: 8

Views: 27511

Answers (2)

Zach L
Zach L

Reputation: 16262

You should put them on your classpath, like

java -classpath someJar.jar YourMainClass

And, of course, you can do the same for javac.

If you need to have more than one jar or directory on your classpath, you'll need to use your platform's default path separator. For example, on Windows,

java -classpath someJar.jar;myJar.jar YourMainClass

On a side note, you might find it easier to use an IDE to manage this sort of stuff. I've personally used just my slightly scriptable editor and have managed fine. But it's good to know how to do this stuff by command line.

Upvotes: 12

Jigar Joshi
Jigar Joshi

Reputation: 240948

javac -cp yourjar.jar YourClass.java

&

java -cp yourjar.jar YourClass

You need to make all required jar available in classpath , this is how you can do it

Upvotes: 6

Related Questions