用户登录
用户注册

分享至

如何在三个不同的 Java IDE 上检查已安装的 JAR、外部库等?

  • 作者: 霜霜她大姨妈
  • 来源: 51数据库
  • 2023-01-29

问题描述

我用多种语言编写过程序,并辅导过计算机科学的学生,但我刚开始在我的 MacBook 上学习 Java.关于这个问题,我很高兴有任何答案指向我解决我的问题的可用信息或教程;我能够理解高级的东西.

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.

我一直在寻找适合我的 IDE 以及可以与我的学生一起使用的东西,并且我尝试过 IntelliJ、Eclipse 和 VS Code.在此过程中,我安装了外部 JAR 以提供额外的功能,例如 Apache Commons.

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.

事情变得越来越混乱.我已经忘记了我是如何在每个 IDE 中达到当前状态的.我想更好地了解如何了解任何给定项目在这些 IDE 上使用的整体 Java 环境,包括任何外部 JAR 及其所在的位置.而且我想知道他们是否借用了Java系统环境.

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.

我还想就安装外部 JAR 的正确方式或最简单/最干净的方式提出建议.

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

推荐答案

所有 IDE 都需要一种方法来了解项目的依赖关系.你可以自己告诉他们,也可以让构建工具来做.

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.

手动依赖处理:通过将 jars 添加到您的项目中.当一个开发人员在一个特定的 IDE 上处理一个小项目时,这可能是最快的方式,几乎没有依赖关系.通常当告诉 IDE 这个 .jar 是您项目的依赖项时,IDE 会存储对项目特定文件的引用(例如,在 Eclipse 中,您可以使用 txt 编辑器编辑 .classpath 文件并自己查看依赖项).但是,它会将您的应用程序锁定到您的 IDE.大多数 IDE 都支持跨 IDE 导入和迁移,但是当一个依赖项添加到一个并且必须重复添加到另一个时,同时使用两个 IDE 可能会令人困惑.此外,您的依赖项本身具有依赖项.通过手动添加您的 jar,您也有责任查找和下载它们自己的依赖项.

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.

使用构建工具: 目前有 3 个标准的此类工具:ApacheAnt 与 Ivy、Apache Maven 和 Gradle.它们都支持 Java 的主要 IDE:IntelliJ IDEA、Eclipse 和 NetBeans.它们都使用一些额外的构建工具特定文件来存储您的项目配置,然后配置您的 IDE 和特定于 IDE 的文件.这样,您的项目变得与 IDE 无关,IDE 将依赖项处理外包给构建工具.这些工具会将您项目的任何直接或传递依赖项下载到本地目录中,或者您可以在指定文件夹中编译 jars.其中,Ant 是最古老的(Ivy 添加了依赖处理支持),Maven 是在那之后开发的,Gradle 是最新的,可能是最灵活的.然而,在生产中,Maven 是目前最成熟的一个.查找 标准也很有用目录布局.如果你坚持这一点,使用 Maven 或 Gradle 会更容易工作/开始.

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.

最后,您可以在 Maven-Central 中搜索并找到大部分免费库,方便他们的 Ivy还添加了/Maven/Gradle 脚本,供您在构建工具脚本中使用.在许多情况下,如果您希望手动将其添加为依赖项,也会提供 .jar.

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.

关于 VS Code,我认为它通过插件支持这些工具,但我不确定.

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

软件
前端设计
程序设计
Java相关