coffeemonitor
coffeemonitor

Reputation: 13150

Sharing user libraries between projects

I'm taking some time to learn Eclipse, and later on NetBeans. I actually enjoy both IDEs. I don't know which one I prefer, but they seem to be intuitive.

As for the Eclipse IDE, I'm learning about best practices for sharing my User Libraries amongst all my projects. Not to mention when I find someone else's Java code online, I certainly would like to import that code and utilize it in any place I need.

I notice there's many questions on Stack Overflow about how to share assets among all the Projects.

To be clear, when I say "assets", I mean anything other than where I would have my Project's main method reside. (ie: images, xml/txt files, custom classes, etc....)

I come from the web development world (PHP), so my mindset is accustomed to PHP's include() and require() functions, for importing anything on the server into my application. Like most web developers I know, I keep my web assets in the same places for ease of importing.

Now onto a new world, Java + Eclipse.

I've created a single Project, and I am now creating additional Classes within that single Project. These Classes could be useful in practically every Project I create.

After reading other questions and posts I'm still not quite sure of a Best Practice for asset sharing between Projects. (I'm only concerned about a single workspace too)

I'd like to hear from others about their personal Best Practices.

Do you create a Project that holds only Classes, Images, Files?

Do you keep a Folder/Directory somewhere on your File System that keeps all of that, and you import it?

Do you utilize Eclipse's default settings when creating a Project, or do you change anything around?

Upvotes: 3

Views: 5554

Answers (2)

Shridutt Kothari
Shridutt Kothari

Reputation: 7394

There is another better way of doing it.

Using Projects as dependencies for other Projects may seems easier...
But that should be only done if we want to use that project as library project.

Else if we just want to do sharing user libraries between projects, than following approach is better.

Create Linked Folder containing libraries, as follows:

  1. Right click on project.
  2. Click on New, and select new folder.
  3. Go to advance.
  4. Choose your lib directory.
  5. Click on ok.
  6. Right click on project.
  7. Go to properties.
  8. Go to Java Build Path.
  9. Go to libraries tab.
  10. Click on Add Jars... and import required jars from /libs directory.
  11. Click on ok.

Upvotes: 0

reprogrammer
reprogrammer

Reputation: 14728

You can put the shared libraries in an Eclipse projects P and make other projects depend on P. To make a project Q depend on P do the following:

  1. Select project Q in the package explorer, and right-click on it.
  2. Select Properties from the context menu.
  3. Go to the Java Build Path properties page.
  4. Go to the Projects tab.
  5. Check project P to add it to the build path of project Q.

See the article at http://www.informit.com/articles/printerfriendly.aspx?p=367962 for more details.

Upvotes: 7

Related Questions