Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 489
Sandeepan Nath Avatar asked Jan 19 '11 07:01

Sandeepan Nath


2 Answers

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.

like image 95
Zach L Avatar answered Nov 05 '22 17:11

Zach L


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

like image 39
jmj Avatar answered Nov 05 '22 16:11

jmj