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

I am new to Java (mostly a LAMP developer). I got this JAVA API to parse .pst files and display all incoming messages.

I tried to execute the given .class file, but it throws exceptions. I need to add / link to some .jar files provided by the API.

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

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

So what configuration do I need to do? Or is it better to get an Eclipse IDE? I just have one .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 android project from command line

How to include external JARs in your own project JAR

+4
source share
2 answers

You should put them in your classpath, for example

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 in your classpath, you need to use your default separator. For example, on Windows,

java -classpath someJar.jar;myJar.jar YourMainClass

On the other hand, it might be easier for you to use the IDE to manage things like this. I personally used only my script editor and did a great job. But it's good to know how to do this using the command line.

+10
source
 javac -cp yourjar.jar YourClass.java 

&

 java -cp yourjar.jar YourClass 

You need to make all the necessary jar available in classpath, here is how you can do it

+6
source

Source: https://habr.com/ru/post/1336099/


All Articles