0

Semi-greenthumb here. I'm looking to download some Apache Commons and Google Guava libraries to use in Eclipse. Multiple Q&As (example, example) have said to download the library myself, and then either load it in Eclipse by path as a "User Library" that I can add manually to projects or go through an automated project management plugin like Maven. However, that leaves the question, where should I actually store the library on my system? (Mac OS)

Ideally, I want it in a directory that is common to all Mac/*NIX systems. However, this Q&A seems to suggest that doing so would be a bad idea, and this comment implies that I should keep a separate copy of the library within each project that uses it. This seems like it would be both a waste of space (for projects that use the same library version), as well as make linting Java files in a separate text editor a hassle due to libraries being stored within an Eclipse project's file structure rather than at the system level.

So where should I put 3rd party Java libraries?

Community
  • 1
  • 1
Travis
  • 2,135
  • 17
  • 29
  • 1
    As Cristian said, I would recommend Maven as well. It handles everything you just talked about automatically, and it makes it easy to switch versions/upgrade to newer versions etc. without worrying about handling the Jars yourself. – Alex Feb 08 '17 at 21:17

2 Answers2

2

I faced the same issue when I was maintaining my project dependencies in a manual way. It is difficult to have control over them, and sometimes updating a library can be a really painful experience if that update breaks a transitive dependency.

All this pain went away when I switched to Maven.

When you configure Maven, you can set the directory where these libraries will reside (common path is {user.dir}/.m2 } and every time a dependency is added to a project (via POM), then Maven will check if that library is already downloaded. If not, it will download it and store it for any future use (of the same version). It also resolves transitive dependencies for you, so you don't have to worry of breaking it when manually replacing a JAR.

This way you don't have to worry where the libraries are, your IDE will reference them automatically using the apropiate Maven plugin

I'm not saying you should use Maven, but if your problem is managing dependencies, then Maven (or any other dependency management system, eg: Gradle) may help you.

Cristian Meneses
  • 4,013
  • 17
  • 32
2

The comment you cited is pretty naïve in its approach. There are far too many build management tools to handle dependencies without having to deal with these minutiae.

If you decide on a tool such as Maven, your dependencies will be downloaded into a specified local repository (a directory on your filesystem), and all Mavenized applications can easily be configured to use those (shared) artifacts.

Most Java supported IDEs like Eclipse come with the option to initialize projects with Maven (or Gradle, as another example) and have sleek interfaces to easily edit their configuration files to specify which dependencies your projects will use.

I would strongly recommend either of those as opposed to manual JAR/artifact management, even for basic personal tinkering projects.

Keith
  • 3,079
  • 2
  • 17
  • 26