鍦ㄤ嬌鐢╫sgi瀹炵幇鏃?鍙互浣跨敤璇稿install,start,stop榪欐牱鐨勫懡浠ゆ潵綆$悊bundle鎴栬呰皟鐢ㄦ湇鍔?鏈夋椂鎴戜滑鍙兘鎯蟲坊鍔犱竴浜涜嚜瀹氫箟鍛戒護(hù).鍙互閫氳繃濡備笅鐨勬楠ゆ潵瀹炵幇
1.緙栧啓涓涓湇鍔★紝瀹炵幇濡備笅鐨勬帴鍙?/p>
1
public interface CommandProvider
{
2
/** *//**
3
Answer a string (may be as many lines as you like) with help
4
texts that explain the command.
5
*/
6
public String getHelp();
7
8
}
濡傛灉鎯沖畾涔塰ello鏂規(guī)硶,鍙互濡備笅瀹炵幇璇ユ帴鍙?
import java.util.Dictionary;
import java.util.Properties;

import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;

public class Activator implements BundleActivator,CommandProvider
{
BundleContext bundleContext=null;

public void start(BundleContext context) throws Exception
{
System.out.println("start
" +context.getBundle().getLocation());
bundleContext=context;
context.registerService(CommandProvider.class.getName(), new AntherCommandProvider(), null);
Dictionary dictionary=new Properties();
dictionary.put(Constants.SERVICE_RANKING, 10);
context.registerService(CommandProvider.class.getName(), this,dictionary);
}


public void stop(BundleContext context) throws Exception
{
System.out.println("end
" +context.getBundle().getLocation());
}


public String getHelp()
{
return "you are using the help command";
}
public void _helloa(CommandInterpreter intp)

{
intp.println("helloa "+ this.getClass().getName());
}

public void _hello(CommandInterpreter intp) throws Exception
{
intp.println("hello " + this.getClass().getName());
}
}
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;


public class AntherCommandProvider implements CommandProvider
{

public void _hello(CommandInterpreter intp)

{
intp.println("hello "+ this.getClass().getName());
}

public String getHelp()
{
return null;
}
}

鍏朵腑,閫氳繃CommandInterpreter綾誨瀷鐨刵extArgument()鏂規(guī)硶鍙互榪唬鍑烘墍鏈夌殑鍛戒護(hù)鍙傛暟.
2.娉ㄥ唽鏈嶅姟
濡傛灉涓嶅皢璇ユ帴鍙f敞鍐屼負(fù)鏈嶅姟錛岃繖涓猦ello鍛戒護(hù)灝嗕笉浜х敓浠諱綍浣滅敤.娉ㄥ唽鐨勬湇鍔″悕縐板繀欏繪槸org.eclipse.osgi.framework.console.CommandProvider.
褰撶郴緇熶腑瀛樺湪澶氫釜姝ゆ帴鍙g殑瀹炵幇鏃?鍙互閫氳繃SERVICE_RANKING灞炴ф潵鍐沖畾浜嗗懡浠ゆ墽琛岀殑欏哄簭,鏃㈡湁鏈楂樺肩殑鏈嶅姟灝嗚浼樺厛鎵ц.榪欑鏂瑰紡鍙互閲嶈澆緋葷粺涓凡緇忓瓨鍦ㄧ殑鍚屽悕鏈嶅姟.
3.鎵ц鍛戒護(hù)
璇蜂粩緇嗕綋浼?xì)杈撳嚭缁撴?br />


]]>