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

前端 未结 2 1427
轻奢々
轻奢々 2021-01-21 15:53

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

相关标签:
2条回答
  • 2021-01-21 16:11

    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.

    0 讨论(0)
  • 2021-01-21 16:26

    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.

    0 讨论(0)
提交回复
热议问题