Sybase Business Intelligence Solutions - Database Management, Data Warehousing Software, Mobile Enterprise Applications and Messaging
  Worldwide [change] Contact Us  |  MySybase  |   |  Shopping Cart - Buy Sybase Application Servers & Wireless Applications  
CATEGORIES
ARCHIVES
Sybase Blog Center
Sybase Blog Center

Enabling command-line applications for your Eclipse projects

Hi all...

 
Recently in DTP we came across an opportunity to provide admin-level support for some import/export type functionality within Connectivity. And it was discussed that this would be best done as a command-line application, since administrators may not have access to or wish to use the full blown Eclipse UI to handle this task.
 
So we started doing some digging and discovered that there's this very cool framework within the Eclipse platform to handle just this kind of thing. A bit of Googling turned up this presentation from EclipseCon 2006: 
"Hello World" as a Headless Eclipse Plug-in by Jeffrey Fredrick (http://www.eclipsecon.org/2006/Sub.do?id=293)
 
Though the Eclipse platform has changed a bit since Jeffrey wrote his article, it got me going the right direction. So I thought we'd update it for Eclipse 3.3.2.
 
Here's the steps we did to create this sample project...
 
1) Create a new plug-in project.
 
 
 
 
2) Make sure to un-check the "This plug-in will make contributions to the UI" checkbox.
 
3) Uncheck any available plug-in templates.
 
And voila, you have a new plug-in.

4) Go to the Extensions tab of the Plug-in/Manifest Editor. Add a new Extension. Select the "org.eclipse.core.runtime.applications" extension point. Click Finish when you're done.
 
 
You have a new "application" node beneath your org.eclipse.core.runtime.application extension.

 
5) Select the actual extension point node in the tree and note the ID of the application. This is important (I learned this the hard way). You want to provide something unique here that's not too long. It gets prefaced by the ID of your plug-in when you try to run it later.
 
 
It defaults to "idX". Call it whatever you want. In this case, we'll call it "CoolApp". The full ID is then my.cool.application.CoolApp when we go to run this later.
 
 
6) Go back to the "application" node, right-click and click New->Run. This adds the node that specifies the class you're going to run in command-line mode when you invoke your plug-in application.
 
7) Click the class* link to create the application class. Our application class will implement the org.eclipse.equinox.app.IApplication interface. Give it a name ("CoolApplication" in our case) and click Finish.
 
 
So you end up with the beginnings of your application class:
 
 
8) In our case, we're just testing out this functionality, so we don't have to get too fancy. In the Start method, you get an IApplicationContext object, which gives you a whole lot of information about the command line parms that were passed in.
 
So we're going to add some code to check out those command line parms and just write them out intelligbly.
 
public Object start(IApplicationContext context) throws Exception {
 
   // get the arguments
   Map args = context.getArguments();
 
   if (args.isEmpty()) {
      // if there were no arguments, simply write "hello cool world"
      System.out.println("hello cool world...");
   } else {
      // otherwise iterate through the arguments and print them as
      // "key = value" pairs after "hello cool world"
      Iterator iter = args.keySet().iterator();
      while (iter.hasNext()) {
         Object key = iter.next();
         String output = new String();
         if (key instanceof String) {
            output = output + (String) key + "=";
         }
         Object value = args.get(key);
         if (value instanceof String) {
            output = output + (String) value;
         }
         System.out.println("hello cool world, " + output);
      }
   }
 
   // And now we can attempt to get some input and respond from stdio
   BufferedReader stdin = new BufferedReader
     (new InputStreamReader(System.in));
   String message; // Creates a variable called message for input
 
   System.out.print ("Enter the message : ");
   System.out.flush(); // empties buffer, before text is input
   message = stdin.readLine();
 
   System.out.print("You ");
   System.out.println("entered : " + message);
 
   // make sure to return an OK message
   return EXIT_OK;
}
 
So now we save our class, make sure everything compiles and builds.
 
9) Then we export it as a deployable plug-in.
 
 
Pick the directory where you want the jarred plug-in to be written to. In my case, I want it to be installed directly in my Eclipse plug-ins directory (the "plugins" directory is added after the directory you specify as the destination). If you put the exported plugin somewhere else, you'll have to copy it into your Eclipse/plugins directory manually. Click Finish and it will put the plug-in where you specified.
 
 
10) Now head out to a console window. Assuming you have your Java environment set up correctly, all you should have to do to run the application is go to your Eclipse directory and type:
 
eclipsec -nosplash -application my.cool.application.CoolApp
 
 
And that's all there is to it! I know we're going to look into using this sort of application in the future to provide some command-line import/export functionality when we get a chance.
 
Hope this helped you out. The Eclipse Platform has lots of cool bits that most of us User Interface people never see!
 
Until next time... Keep on programming!
--Fitz


Hi there...

Hi there...

This blog is a small window into some of the things going on related to the Data Tools Platform (DTP) project at Eclipse. I've been involved with DTP since it began and actually wrote some of the code that made it into the very first release. Since then, I've become more and more involved, to the point where I recently became the PMC Lead for DTP as well as the Connectivity sub-project team lead. (Yes, I wear many hats like many of the folks in the Eclipse community.)

I hope to be able to write about cool things going on in the DTP community as well as provide some code examples, samples, and commentary on open source in general.

So welcome to my little part of the blogosphere!

--Brian Fitzpatrick (aka Fitz)


Sybase at EclipseCon this week

Sybase is one of the silver sponsors for EclipseCon2008. Some of us will be at the sybase booth. Note that the exhibit hall pass is free
and you can sign up online. DTP and Sybase are going to be represented in various talks and tutorials. Please stop by if you've any
DTP/Sybase questions. You may also want to stay for one of the evenings as most of the evenings there is a party
sponsored by one of the companies. Stop by at the booth if you just want to find out which is the cool party ..)


Tutorials
- Implement Schema Editing Based on Delta DDL (Dafan Yang, Sybase)
- Data Applications in Eclipse: The Eclipse Data Tools Platform (Sheila Sholars, Loic Jullien, IBM; John Graham, Sybase)
- Enabling support for a new database or data source in Eclipse (Philippe Ombredanne, EasyEclipse/nexB)

Long Talks
- Introducing DTP Open Data Access Framework (Linda Chan, Actuate)
- Introducing the DTP SQL Query Builder (Brian Payton, IBM)

Short talks
- Creating Windows Mobile Database Applications with Eclipse (Jose Ramos, Sybase)
- Push for Usability of Data Tools Wizards (Brian Fitzpatrick, Sybase)
- DTP Help-Helper Plug-in (John Graham, Sybase)


TechWave 2008 Call for Papers... Now open

We are now accepting speaker proposals for the 60 and 90 sessions at the upcoming Sybase TechWave conference August 4 - 8th 2008.

(More...)


SYS-CON.TV Interview from SOA World 2007 East

SYS-CON.TV Interview 

My SYS-CON.TV Interview from the SOA World Conference East 2007, June in NYC, has been posted on 

http://tv.sys-con.com/read/418876.htm

Check out what I say about Sybase in SOA and more

Ian


Ready... Set... Go!

Is it that time of year, again?

It seems that, only a few days ago, we finished TechWave 2006.  Now here we are at TechWave 2007.  New hotel, new look, and a lot of new things to talk about...

(More...)


Considering WorkSpace for database development

We recently published a whitepaper titled "Evaluation and Getting Started Guide for Database Development Tooling in WorkSpace." You can access the PDF version from the bottom of this page. 

(More...)


Come see us at TechWave

We here in the WorkSpace team are excited about going to TechWave and opportunity to talk to our customers, about upcoming WorkSpace 2.0 release and get feedback. We welcome your suggestions for the future as well.

(More...)


Welcome to Development 2.0

"The brain is a wonderful organ.  It starts working the moment you get up in the morning and does not stop until you get into the office."  - Robert Frost

Welcome to Development 2.0. 

When Sybase came to me and said "we would like you to blog on development, open source, and all manners of trends in the industry" I thought to myself "Excellent!"  Followed immediately by "what am I thinking?"  They want me to discuss the future of development?  Well, absolutely.  Here goes...

(More...)


JavaOne could learn a thing or two from EclipseCon

After having spent whole day at JavaOne, this is what I figured was missing. It needs to be more like the old days of J1 or like the present days of EclipseCon.

(More...)