开发者

Installing Java libraries

As I'm quite n开发者_如何学Goew 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.


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.


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...


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


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜