Installing Java libraries

17,405

Solution 1

Java libraries don't really need to be 'installed' like other applications. All you need to do is put the jar file in a specific location, and add the jar file to your classpath. How you do that depends on the linux distro you are using. If you are making a web application in eclipse, you can drop the .jar file in the WebRoot/web-inf/lib folder, and it will be bundled in with your project.

Solution 2

Be sure that the path, which you place the libaries at, is set in the $CLASSPATH Environment Variable.

For Eclipse: Project -> Properties -> Java Build Path -> Add JARs...

Solution 3

It's up to you really - I use /opt/javalib, but you might consider a directory in /usr/local as well.

Solution 4

You can store them wherever you wish. You can store them within the JRE distribution directories, but I wouldn't recommend that.

Instead I would store them per-project (so you can have different versions for each project easily - some libraries have different names for each version, some don't) and adopt a standard such as a lib/ directory. That way you can have standard build scripts (Ant etc.) that can operate in the same way (if you're using Maven, then there's a standard place per-project - src/main/resources)

Solution 5

You could use Maven to manage any dependencies to those libraries. Maven will automatically download all needed JAR files and put them in a local repository (the location is configurable).

This makes upgrading to new versions of various libraries very easy as you just declare the version you want and Maven does the rest.

Beware: Maven is something to get used to and the initial learning curve is steep. The rewards come if you have everything set up properly and maven takes care of compiling, packaging, distribution, site creation, release management etc. etc. etc.

Share:
17,405
snoofkin
Author by

snoofkin

Developer...............C/C++.......Perl.......XSLT......Bash.......etc.... Concentrating mainly on Perl & C++ and Qt.

Updated on June 09, 2022

Comments

  • snoofkin
    snoofkin about 2 years

    As I'm quite new to Java, I would like to know the proper procedure of installing new libraries (those that are no available in my linux dist repositories). Where should I place them? and how to install them? For instance, I downloaded openCsv (http://opencsv.sourceforge.net/), and I have no idea how to install it.

  • snoofkin
    snoofkin over 13 years
    and them, what do I need to add to Eclipse in order to make my application compile?
  • snoofkin
    snoofkin over 13 years
    but openCSV has couple of jars, how do I know which one to link in Eclipse?
  • trojanfoe
    trojanfoe over 13 years
    You add them as 'user libraries'
  • Jeremy Vanderburg
    Jeremy Vanderburg over 13 years
    I would start with the opencsv-2.2.jar file. That might be the only one you need.