views:

45

answers:

2

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

+1  A: 
Mondain
And the import command would look something like 'import packageName.className'?
Jonathan
If your "Library" contains classes in the package"com.example.myapp"and your "Project" was in the same or different package, the imports would still look like so:"import com.example.myapp.*;"
Mondain
Now when you deploy your application from "Project" you will need to make sure the classes in "Library" are available. This answer is only for when Developing, Debugging, or Running within Eclipse.
Mondain
+1  A: 

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

Jjub