Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Eclipse Plug-in Development

You're reading from   Mastering Eclipse Plug-in Development Build modular applications on Eclipse by defining custom extension points and using OSGi services

Arrow left icon
Product type Paperback
Published in Aug 2014
Publisher
ISBN-13 9781783287796
Length 362 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Bandlem Limited Bandlem Limited
Author Profile Icon Bandlem Limited
Bandlem Limited
Alex Blewitt Alex Blewitt
Author Profile Icon Alex Blewitt
Alex Blewitt
Arrow right icon
View More author details
Toc

Extending the shell


There are two different ways of extending the shell. One of them is to use the osgi:addcommand function that comes with Gogo. This allows one or more static methods from a class to be defined as functions in the console. Another way is to write custom Java classes and register them as OSGi services.

Adding commands from existing methods

In Java, the Integer class has a static method called toHexString, which converts an integer into its hexadecimal representation. Although this can be invoked via method calls, it is easier if it can be added as a command natively to the console.

The osgi:addcommand command takes a prefix (scope), a class object, and optionally a method to import. Without the last parameter, all public static methods will be added as commands.

Note

When Gogo starts, it runs the gosh_profile script that uses this technique to add the methods of the System class under the system scope.

Getting a class from an existing instance

There are two ways to acquire a class...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image