Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java best practices of placing and linking external JARs in a Eclipse project?

I'm just getting back into Java and I've been trying to figure out how exactly I should be organizing my project. I come from a C# background where you just have to make sure that the libraries you compile are retrievable by the executable (or other libraries) by keeping them in the same folders or subfolders, but java seems to do things differently.

In my Eclipse workspace I have my main project I'm working on (just one for now, more later) and it references external JARs (in my case, the gazillion of files of Apache Axis2).

Where should I be storing these libraries that my projects depends on when building? I will need to add everything to source control really soon, and so I can't keep referencing these JARs by absolute path on my machine. I read suggestions for putting this IN a subfolder of my main project, but I feel that's not ideal. I think I should be keeping them in the same source-controlled parent folder as the project, and somehow reference them through relative path (eclipse one does absolute path through the UI, really?), so something like:

c:\JavaProjects\MyProject c:\JavaProjects\axis2-1.5.4 c:\JavaProjects\%whatever other library%

Is there an even better way?

like image 568
Alexandr Kurilin Avatar asked Dec 17 '22 15:12

Alexandr Kurilin


1 Answers

Ideally, you shouldn't be storing the libraries in your project. They can be retrieved by public (or private) repositories via so called dependency-management tools. The two most prominent ones are Maven and Ivy.

Eclipse (and any other IDE) has integration with these tools (via plugins) and adds the desired libraries to the classpath automatically. You only have to define them (together with their version) in a configuration file.

like image 76
Bozho Avatar answered Apr 26 '23 18:04

Bozho