开发者

Eclipse - Importing your own library

开发者 https://www.devze.com 2023-01-14 12:44 出处:网络
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 l

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.

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;')

Thanks,

Jonathan


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

  • 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

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


There are several ways:

A. Import source files

  • 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

B. Import Jar When 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:

  • 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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消