I've been a zone leader with DZone since 2008, and I'm crazy about community. Every day I get to work with the best that JavaScript, HTML5, Android and iOS has to offer, creating apps that truly make at difference, as principal front-end architect at Avego. James is a DZone Zone Leader and has posted 639 posts at DZone. You can read more from them at their website. View Full User Profile

Plugin and Play - Integrating YouTube with Eclipse

  • submit to reddit

The Plugin Development Environment

For plug-ins, the MANIFEST.MF file is visualised and broken up into sections. The Overview page provides launch links so that you can run you plugin from there. This is a useful feature as it saves you from having to configure your own Run configuration.

The first thing we need to do is set up our Dependencies so that we can use the Google APIs for YouTube. To set up the classpath go to the Runtime tab in you MANIFEST.MF viewer and add the following jars from the Google API download.

  • gdata-core-1.0.jar
  • gdata-youtube-1.0.jar
  • gdata-media-1.0.jar
  • gdata-client-1.0.jar

You’ll also need to include mail.jar from the JavaMail distribution.

Create a New Menu

We’ll create a YouTube menu to invoke our code from. This section outlines how to create such a menu.
To create menus in Eclipse you need to use the Menu Contributions framework.

To use an extension point, you will need to go to the Extensions tab. Here you need to add a new org.eclipse.ui.menus extension by clicking on the Add button.
























When you click on Finish you will see a new node in the list of Extensions named org.eclipse.ui.menus. Right-click on this node and choose New Menu Contribution, and in the locationURI field, We will choose to have the menu placed in a section set aside for additions - menu:org.eclipse.ui.main.menu?after=additions

Now that we’ve defined the location of our contribution, we need to define the menu itself. This time, right-click on the new contribution node in the Extensions list and choose New/ Menu. The only required field here is the text that will be displayed on the menu, which we’ll call “You Tube”.

This will cause the node to be renamed to YouTube. Right click on that node and choose to add a new command. Provide this with the label “Search” and change the commandID to something other than the default.
In this example I use com.eclipsezone.youtube.searchcommand as the id.



Now we need to associate that commandID with a command, so add a new org.eclipse.ui.commands extension.
























From the new node, create a new command that matches the commandID you provided previously and give the command a more readable name.

From this screen you can set up the handler for the command – this is the class that will get activated to run our You Tube action. Simply click on the defaultHandler link and Eclipse will provide a wizard to create the new class implementing the IHandler interface from the commands framework.



At this point, if you run the project, using the Overview tab and choose the launch option, you should simply see the new menu, with the search item underneath.

A useful tip for running your applications is to add the –consoleLog argument to the runtime configuration. You can add this by clicking on the Run… menu item, and add the argument to the Program Arguments field. Adding this will cause all logging and other messages to be displayed on the console tab.

Now that we have defined our extension points and created our menu items, it’s time to start writing our YouTube interaction code.