如何告诉 Eclipse 为所有项目包含标准 .jar 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4911554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:44:08  来源:igfitidea点击:

How to Tell Eclipse to Include Standard .jar Library for All Projects

javaeclipsejar

提问by themaestro

I realize that in eclipse you can specify certain .jar libraries to add for individual projects, but I was wondering if it was possible to make it such that eclipse automatically adds standard .jar's to the classpath for all projects. I'm using eclipse for a java course and would like to be able to automatically use the course's stdlib for all projects.

我意识到在 eclipse 中,您可以指定某些 .jar 库来为单个项目添加,但我想知道是否有可能使 eclipse 自动将标准 .jar 添加到所有项目的类路径中。我正在将 Eclipse 用于 Java 课程,并希望能够为所有项目自动使用课程的 stdlib。

采纳答案by Konstantin Komissarchik

Under Window -> Preferences -> Java -> Installed JREs find your default JRE (the checked one) and hit Edit. Add jars that you want.

在 Window -> Preferences -> Java -> Installed JREs 下找到您的默认 JRE(选中的那个)并点击 Edit。添加所需的罐子。

回答by Phani

By default, if it's a java project then eclipse includes required jar files, but in addition if you need more jars then you could create user libraries by

默认情况下,如果它是一个 java 项目,那么 eclipse 包含所需的 jar 文件,但此外,如果您需要更多 jar,那么您可以通过以下方式创建用户库

Window - Preferences - Java - Build Path - User Libraries.

窗口 - 首选项 - Java - 构建路径 - 用户库。

rather mixing JDK jars with user libraries.

而是将 JDK jar 与用户库混合。

回答by whatnick

You can adapt a dependency control and build system like mavenand put your dependency jars are properties for the maven modules. This way maven is in charge of putting the jars in a shared place in the maven repository and reusing them across projects. You can then use the Maven eclipse project generator to create your workspace for eclipse. If you project is getting rather big with lots of individual projects in the workspace this is a great automation solution.

您可以调整依赖项控制和构建系统,例如maven,并将您的依赖项 jar 放在 maven 模块的属性中。这样 maven 负责将 jars 放在 maven 存储库中的共享位置并在项目中重用它们。然后,您可以使用 Maven eclipse 项目生成器为eclipse创建您的工作区。如果您的项目变得相当大,工作区中有很多单独的项目,这是一个很好的自动化解决方案。

回答by Bert F

I can't think of a way to do what you want specifically, but what I would recommend, if there were many of these jars, is to create a project to hold these jar files, put them in the projects classpath, and then set the project to export those jar files (that may be the default for jars in the lib directory, I can't remember).

我想不出具体的方法来做你想做的事,但我建议,如果这些 jar 很多,是创建一个项目来保存这些 jar 文件,将它们放在项目类路径中,然后设置导出那些 jar 文件的项目(这可能是 lib 目录中 jar 的默认值,我不记得了)。

Then any new projects can simply add a dependency on this "jar" project to get all the jars in there included in its build path.

然后,任何新项目都可以简单地添加对这个“jar”项目的依赖,以获取包含在其构建路径中的所有 jar。