Eclipse - 导入您自己的库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3632193/
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:04:50  来源:igfitidea点击:

Eclipse - Importing your own library

javaeclipse

提问by Jonathan

Okay, hopefully this is quick and easy.

好的,希望这既快速又简单。

I have two separate java projects, 'Library' and 'Project', and I have a class in 'Project' that wants to implement a method found in 'Library'. I am looking for some kind of 'import' call to make at the top of my 'Project' class, to make the methods found in 'Library' accessible in that project.

我有两个独立的 Java 项目,“Library”和“Project”,我在“Project”中有一个类想要实现“Library”中的方法。我正在寻找某种“导入”调用,以便在“项目”类的顶部进行调用,以使该项目中可以访问“库”中的方法。

How would I do that?

我该怎么做?

On another note, this 'Library' project only exists because I want to use a number of classes of my own to supplement the the usual java libraries (java.util, java.io, etc...). Is there a way I can add my java project to my java libraries? (ie. 'import java.Library.className;')

另一方面,这个“库”项目之所以存在,只是因为我想使用自己的一些类来补充常用的 Java 库(java.util、java.io 等)。有没有办法可以将我的 java 项目添加到我的 java 库中?(即'import java.Library.className;')

Thanks,

谢谢,

Jonathan

乔纳森

采纳答案by Paul Gregtheitroade

Just have "Project" reference your "Library", on windows the process is (using menu / tab names)

只需让“项目”引用您的“库”,在 Windows 上该过程是(使用菜单/选项卡名称)

  • 1. Go to: Project -> Properties -> Java Build Path -> Projects
  • 2. Client Add...
  • 3. Select your "Library" project from the list
  • 4. Click Ok
  • 5. Click the other Ok
  • 1. 转到:项目 -> 属性 -> Java 构建路径 -> 项目
  • 2.客户端添加...
  • 3. 从列表中选择您的“库”项目
  • 4. 点击确定
  • 5.点击另一个确定

Now your done and you can use import for classes in your "Library"

现在你完成了,你可以在你的“库”中使用导入

回答by Jjub

There are several ways:

有几种方式:

A. Import source files

A. 导入源文件

  • Right click your project in the project explorer
  • select Properties-->Java Build Path
  • Click on the Source tab and the Link Source button and add the root folder containing Library and click Finish
  • Now click on the Projects tab and click the Add button to add your 'Library'. Click Ok and you're done
  • 在项目资源管理器中右键单击您的项目
  • 选择属性-->Java 构建路径
  • 单击“源”选项卡和“链接源”按钮并添加包含库的根文件夹,然后单击“完成”
  • 现在单击“项目”选项卡,然后单击“添加”按钮以添加您的“库”。点击确定,你就完成了

B. Import JarWhen you compile your eclipse project it creates a jar for your project in the 'Build' subfolder of the root directory of your project. To import that in you current project:

B. 导入 Jar当您编译 eclipse 项目时,它会在项目根目录的“Build”子文件夹中为您的项目创建一个 jar。要将其导入当前项目:

  • Again Right click your project in the project explorer
  • Select Properties-->Java build Path
  • Click on the Libraries tab and click Add External JARs. Navigate to the folder containing Library.jar and click Finish and click Ok
  • 再次在项目资源管理器中右键单击您的项目
  • 选择属性-->Java 构建路径
  • 单击库选项卡,然后单击添加外部 JAR。导航到包含 Library.jar 的文件夹并单击完成并单击确定

You should now be able to import your names from your Library Project

您现在应该能够从您的图书馆项目中导入您的名字