简体   繁体   中英

How do I check installed JARs, external libraries, etc. on three different Java IDEs?

I've written programs in several languages and have tutored students in computer science, but just starting to learn Java on my MacBook. Regarding this question, I'd be happy with any answer that points me to available information or tutorials that address my question; I'm capable of understanding advanced things.

I've been searching for the right IDE for me as well as something I can use with my students, and I've tried IntelliJ, Eclipse, and VS Code. Along the way I've installed external JARs to provide extra capabilities, such as Apache Commons.

Things are getting confusing. I've lost track of how I got to the present state in each IDE. I'd like to understand better how to know the overall Java environment that any given project is using on each of these IDEs, including any external JARs and where they are located. And I'd like to know if they borrow from the Java system environment.

My goal is to understand how my own system got to the way its currently configured, to update my configuration on a project-by-project basis, and to help my students get a matching configuration.

I'd also like advice on the right way, or simplest/cleanest way, to install external JARs.

Maven

Question : I'd also like advice on the right way, or simplest/cleanest way, to install external JARs.

If you really wanna work in a organised way and wanna focus completely on coding rather than looking for dependencies to work with , then try building your projects with Apache Maven . The magic wand of Maven projects are pom.xml file where all magic happens depending upon your wish.

Maven is a build automation tool used primarily for Java projects. Maven addresses two aspects of building software:

  • Describes and manages how software is built.
  • Describes and manages dependencies (various libraries used by your code).

Why Maven:

  1. De facto standard
  2. Able to compile, test, pack and distribute source code ( different Goals )
  3. Robust dependency management (Most important from my point of view)
  4. Extensible via plugin
  5. Good community support and many fan boys around.
  6. The big 3 IDEs (IntelliJ, NetBeans, and Eclipse) all having good support for Maven, letting you use Maven as a substitute for their own proprietary project definition and build process.
  7. Maven famously caches all of its dependencies in the ~/.m2 directory, which is sometimes called the local Maven repository. Maven local repository keeps your project's all dependencies (library jars, plugin jars etc.). When you run a Maven build, then Maven automatically downloads all the dependency jars into the local repository. It helps to avoid references to dependencies stored on remote machine every time a project is build.

You can simply deploy your project as JAR , WAR , or EAR file and use it on different IDEs or as standalone.

All IDEs need a way to know your project's dependencies. You can either tell them that yourself or let a build tool do that.

Manual dependency handling: by adding the jars to your project. This is probably the fastest way when working on a small project, with one developer, on a specific IDE, with few dependencies. Usually when telling the IDE that this .jar is a dependency of your project, the IDE stores that reference to a project-specific file (eg. in Eclipse the .classpath file which you can edit with a txt editor and see the dependencies yourself). However, it kind of locks your application to your IDE. Most IDEs have cross-IDE support for import and migration, but using both IDEs at the same time can be confusing when a dependency is added to one and has to be repetitively added to other as well. Furthermore, your dependencies have dependencies on their own. By adding manually your jars you are responsible to find and download their own dependencies as well.

Use a build tool: There are 3 standard such tools right now: Apache Ant with Ivy , Apache Maven and Gradle . All of them have support in the major IDEs for Java: IntelliJ IDEA, Eclipse and NetBeans. All of them use some extra build-tool specific files to store your project's configuration and subsequently configure your IDE and the IDE-specific files. That way, your project becomes IDE-agnostic, the IDE outsources the dependency handling to the build tool. These tools will download any direct or transitive dependencies of your project in a local directory or you can compile jars in a specified folder. From those, Ant is the oldest (with Ivy adding dependency handling support), Maven was developed after that and Gradle is the newest and probably the most flexible. In production however Maven is by far the most established one right now. It would be also useful to look up the Standard Directory Layout . If you adhere to that, it will be easier to work/start with either Maven or Gradle.

Finally, you can search and find most of the free libraries in Maven-Central where conveniently their Ivy/Maven/Gradle script is added as well for you to use on your build-tool script. In many cases a .jar is provided as well if you prefer to manually add it as a dependency.

Regarding VS Code, I think it supports these tools through plugins but I'm not sure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM