Twitter github

An Eclipse-based Facebook Application (Part 1)

So, the first thing I do when I write an Eclipse-based application, or any application for that matter is set a quick baseline of what I want done. For my first milestone, I decided I simply wanted to be able to log into Facebook. I figured, this would be a good start… it would require me to use the Facebook API in some fashion. This would force me to create a plug-in for the Facebook API which I would reuse when I started to do things like update my status from Eclipse. So my first stop was to look at the Facebook Java APIs since that would make life easier for me.

I found a cool project hosted at Google Code that contained some Java APIs. The only problem was that it seemed you needed a million jars to use these APIs. As an Eclipse plug-in afficiandio, I knew how to handle this… I’ll create a new plug-in! I downloaded all the jars and then launched the ‘New Plug-in Project from Exisiting Jars’ wizard which allows me to quickly create a plug-in by pointing to those existing jars.

To give my newly created plug-in some polish, I’ve decided to do a couple things. First, I’ll only export the packages that my consumers will need to work with the Facebook API:

In the Eclipse and OSGi world, Java packages are the unit of modularity. My consumers shouldn’t care about the other packages and I don’t feel like supporting those packages downstream so I won’t expose them. Since I don’t expose them, my consumers won’t be able to use any classes from those non-exported packages. This provides a nice way to keep your API really “internal.” For my next magic trick, I will make sure to set the Bundle-RequiredExecutionEnvironment (BREE) for my plug-in to J2SE-1.5:

BREEs are a way of telling Eclipse and OSGi that your plug-in at a minimum, requires Java 5.0 to run. This is cool because the Eclipse runtime won’t activate your plug-in if it’s running on Java 1.4… only Java 5.0 and above. The runtime will also give a message out stating that the plug-in can’t activate because the mininum BREE hasn’t been yet… also cool!

So with my new Facebook API plug-in setup and polished to my liking, we can go and start exercising that API in interesting ways. The first way will be finding a way to log-in to Facebook and that will be discussed in Part 2.

  • Lessons Learned
    • Start simple and iterate as you make progress
    • Use the ‘New Plug-in Project From Existing Jars’ wizard to package your dependencies
    • Don’t forget to set BREEs, they can save your consumers some heartache!
    • Export packages from plug-ins that consumers are only interested in


If you like this type of material, let me know. If there’s a good response, that’s usually motivation for me to do things faster.

  • Anonymous

    Very useful kind of post.
    I learned with this one the existence of a wizard allowing to create plugins from jar files!!!

    Manu

  • Anonymous

    Very useful kind of post.I learned with this one the existence of a wizard allowing to create plugins from jar files!!!Manu

  • sud

    This is very helpful for newcomers. I remember when I first got started with Eclipse pLugin development and was lost trying to figure how why you needed separate bundles (plugins) for dependency jars and how to go about creating one.

    Also, another aspect of plugin development that would be useful is best practices on structuring your application (UI, Business, Presentation layers) and how to keep them decoupled for testing etc.

  • sud

    This is very helpful for newcomers. I remember when I first got started with Eclipse pLugin development and was lost trying to figure how why you needed separate bundles (plugins) for dependency jars and how to go about creating one.Also, another aspect of plugin development that would be useful is best practices on structuring your application (UI, Business, Presentation layers) and how to keep them decoupled for testing etc.

  • Jakub Jurkiewicz

    This looks like a great idea! Every newcomer looks for the tutorial which would show how to create Eclipse application from the very beginning to the end.

  • Jakub Jurkiewicz

    This looks like a great idea! Every newcomer looks for the tutorial which would show how to create Eclipse application from the very beginning to the end.

  • Stef

    Keep up the good work!! Looking forward to the next step.

  • Stef

    Keep up the good work!! Looking forward to the next step.

  • Jeune Entreprise Innovante

    I’ve looked at this (REST) api and run the java example client. The first time I logged it callback a facebook webpage URL on my facebook account.

    How bypass this call back and in the same time log to account ?

  • Jeune Entreprise Innovante

    I’ve looked at this (REST) api and run the java example client. The first time I logged it callback a facebook webpage URL on my facebook account.How bypass this call back and in the same time log to account ?