启动篇 (eclipse 3.30代码分析)

本文解析了Eclipse的启动过程,重点介绍了启动类org.eclipse.equinox.launcher.Main的作用及输入参数配置。通过分析eclipse.ini文件和osgi.install.area等属性,阐述了Eclipse如何确定安装位置及配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 启动类

通过查看eclipse.exe文件,可以判断是 org.eclipse.equinox.launcher.Main 
在plugin org.eclipse.equinox.launcher_1.0.1.R33x_v20080118.jar里面
org.eclipse.equinox.launcher.Main作者推荐只能从命令行启动,需要api调用,请使用EclipseStarter
 启动类的输入参数是在 : eclipse.ini文件里面
  • 重要属性 

osgi.install.area: eclipse 安装地方,如果你没有指定,默认是下列代码得到
ProtectionDomain domain = Main.class.getProtectionDomain();
        CodeSource source = null;
		URL result = null;
        if (domain != null)
        	source = domain.getCodeSource();
        if (source == null || domain == null) {
			if (debug)
				System.out.println("CodeSource location is null. Defaulting the install location to file:startup.jar"); //$NON-NLS-1$
			try {
				result = new URL("file:startup.jar"); //$NON-NLS-1$
			} catch (MalformedURLException e2) {
				//Ignore
			}
        }
		if (source != null)
			result = source.getLocation();
		
        String path = decode(result.getFile());
        // normalize to not have leading / so we can check the form
        File file = new File(path);
        path = file.toString().replace('\\', '/');
        // TODO need a better test for windows
        // If on Windows then canonicalize the drive letter to be lowercase.
        // remember that there may be UNC paths 
        if (File.separatorChar == '\\')
            if (Character.isUpperCase(path.charAt(0))) {
                char[] chars = path.toCharArray();
                chars[0] = Character.toLowerCase(chars[0]);
                path = new String(chars);
            }
        if (path.toLowerCase().endsWith(".jar")) //$NON-NLS-1$
            path = path.substring(0, path.lastIndexOf("/") + 1); //$NON-NLS-1$
        if (path.toLowerCase().endsWith("/plugins/")) //$NON-NLS-1$ 
        	path = path.substring(0, path.length() - "/plugins/".length()); //$NON-NLS-1$
        try {
            try {
                // create a file URL (via File) to normalize the form (e.g., put 
                // the leading / on if necessary)
                path = new File(path).toURL().getFile();
            } catch (MalformedURLException e1) {
                // will never happen.  The path is straight from a URL.  
            }
            installLocation = new URL(result.getProtocol(), result.getHost(), result.getPort(), path);
            System.getProperties().put(PROP_INSTALL_AREA, installLocation.toExternalForm());
        } catch (MalformedURLException e) {
            // TODO Very unlikely case.  log here.  
        }
 得出来的结果就是plugins的父目录
osgi.configuration.area: 默认情况是在 ${osgi.install.area}/configuration,
当然你也可以配置,它会从这个目录下面去读config.ini文件
  • API 启动类

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值