Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - Importing your own library

Tags:

java

eclipse

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

like image 547
Jonathan Avatar asked Sep 03 '10 00:09

Jonathan


2 Answers

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"

like image 172
Paul Gregoire Avatar answered Oct 22 '22 04:10

Paul Gregoire


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

like image 26
Jjub Avatar answered Oct 22 '22 02:10

Jjub