Home > Articles > Programming > Java

All about Eclipse Plug-ins

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close Window

Chris LaffraJohn Arthorne

Learn more…

Sorry, this author hasn't written any articles.

Sorry, this author doesn't have anything for sale.

Sorry, this author hasn't posted any blogs.

Official Eclipse 3.0 FAQs

This chapter is from the book
Official Eclipse 3.0 FAQs

FAQ 106: How can I share a JAR among various plug-ins?

Suppose that plug-in A and plug-in B both use xmlparser.jar. In your workspace are two projects (for A and B), each containing a copy of the xmlparser.jar library. This is clearly not ideal: Two copies of the JAR are loaded at runtime, and classes from those JARs will not be compatible with each other, as they are loaded by different class loaders. (You will get a ClassCastException if you try to cast a type from one library into a type from the other library.)

Declaring xmlparser.jar as an external JAR does not work, as there is no easy way during deployment of your plug-ins to manipulate your plug-in’s classpath so that they can see the library. The best way to share libraries is to create a new plug-in that wraps the library you want to share.

Declare a new plug-in, C, to contain the library JAR, and make both plug-in A and plug-in B dependent on plug-in C. Make sure that plug-in C exports its library so other plug-ins can see it:

<runtime>
   <library name="xmlParserAPIs.jar">
      <export name="*"/>
   </library>
</runtime>

When you deploy these three plug-ins, they will all share the same library. Note that in some situations, sharing libraries between plug-ins is not possible. If two plug-ins require different or incompatible versions of the same library, they have no choice but to each have a copy of the library.

Note

FAQ 104 What is the classpath of a plug-in?
FAQ 105 How do I add a library to the classpath of a plug-in?

  • Share ThisShare This
  • Your Account

Discussions

Make a New Comment

You must log in in order to post a comment.

Related Resources

Jennifer  BortelWin FREE iPhone Developer Books and Videos- Introducing @InformIT Giveaways
By Jennifer Bortel on February 5, 2010 No Comments

Apples’s recent iPad announcement made our hearts flutter so we couldn’t resist making an announcement of our own!

Today marks the first ever @InformIT Giveaway!

We’ll regularly post a video like this one profiling spectacular prizes we’re giving away—from books and videos to T-shirts and other exciting stuff. Check out the video below to see the giveaways for today, and then scroll down for more prize details and instructions on how to win them!

Dustin Sullivan"Every OSX developer should have this book on their desk."
By Dustin Sullivan on February 1, 2010 No Comments

That was the sentence Mike Riley ended his recent Dr Dobb's CodeTalk review of Cocoa Programming Developer's Handbook with.

David ChisnallCocoa Tip of the Day, 1/29/10
By David Chisnall on January 29, 2010 No Comments

Don't ignore old versions of OS X.

See All Related Blogs

Informit Network