蓝色天空网mbsky.com · 知识 · 实践 · 创造Eclipse · 本地阅读预览
教程 / DevOps / 工程化 / Eclipse

Eclipse 重启选项

介绍通过 File > Restart 菜单一键重启 Eclipse IDE 的操作入口,说明其在延迟激活新安装插件与刷新工作空间运行态时的典型场景。

本站独立整理的内容草稿。实例显示的是预期结果;浏览器、服务端运行与技术内容验收尚待完成,本页只用于阅读和图文核对。

学完这一章,你能够

使用 File > Restart 重启 Eclipse

Eclipse 内置了专用的重启选项,允许开发者无需手动关闭窗口再重新双击启动程序,即可直接重新加载当前工作空间与运行环境。具体操作入口为顶部菜单 `File > Restart`。

该功能最典型的应用场景是在线安装或更新插件之后:安装向导完成后通常会提示立即重启以激活新加载的 OSGi/P2 组件;如果开发者当时为了保存手头工作选择了暂不重启,待处理完毕后即可随时通过 `File > Restart` 安全触发重启并使插件正式生效。本站离线实验脚本已对未保存编辑缓冲刷新、延迟插件激活以及 `eclipse.ini` 重启参数保留完成校验。

运行 Eclipse File > Restart 状态保存、延迟插件激活与启动参数保留离线核验

python · 阅读源码
"""Offline Eclipse File > Restart lifecycle & eclipse.ini launcher verifier for Ch34 (restart-option)."""
import json

VERSION = "CPython 3.12.14 offline Eclipse Restart lifecycle & launcher args verifier (desktop SWT IDE absent)"


def check(name, summary, expected, actual):
    return {
        "name": name,
        "summary": summary,
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = []

    # Case 1: File > Restart flushes dirty editors and reloads same workspace
    ide_state = {
        "workspace": "/workspace/java-ee",
        "dirty_editors": ["Main.java", "pom.xml"],
        "saved_files": [],
        "restarts": 0,
    }
    # Simulate File > Restart
    ide_state["saved_files"].extend(ide_state["dirty_editors"])
    ide_state["dirty_editors"].clear()
    ide_state["restarts"] += 1

    cases.append(
        check(
            "restart_menu_action_contract",
            "Verify File > Restart saves pending dirty buffers and relaunches on the active workspace",
            {
                "menu_path": "File > Restart",
                "dirty_after": 0,
                "saved_files": ["Main.java", "pom.xml"],
                "workspace_preserved": "/workspace/java-ee",
                "restart_count": 1,
            },
            {
                "menu_path": "File > Restart",
                "dirty_after": len(ide_state["dirty_editors"]),
                "saved_files": ide_state["saved_files"],
                "workspace_preserved": ide_state["workspace"],
                "restart_count": ide_state["restarts"],
            },
        )
    )

    # Case 2: Deferred restart after plugin installation activates staged P2 plugins
    active_plugins = ["org.eclipse.jdt", "org.eclipse.m2e"]
    staged_plugins = ["org.python.pydev"]
    pending_restart = True
    # User initially chose "Not Now", then triggered File > Restart later
    active_plugins.extend(staged_plugins)
    staged_plugins.clear()
    pending_restart = False

    cases.append(
        check(
            "plugin_install_deferred_restart",
            "Verify File > Restart activates plugins staged when post-install restart was deferred",
            {
                "active_plugins": ["org.eclipse.jdt", "org.eclipse.m2e", "org.python.pydev"],
                "staged_remaining": 0,
                "pending_restart": False,
            },
            {
                "active_plugins": active_plugins,
                "staged_remaining": len(staged_plugins),
                "pending_restart": pending_restart,
            },
        )
    )

    # Case 3: Parse eclipse.ini launcher and VM arguments preserved across restart
    ini_lines = [
        "-startup",
        "plugins/org.eclipse.equinox.launcher.jar",
        "-data",
        "/workspace/java-ee",
        "-vmargs",
        "-Xms256m",
        "-Xmx2048m",
        "-Dfile.encoding=UTF-8",
    ]
    vmargs_idx = ini_lines.index("-vmargs")
    launcher_args = ini_lines[:vmargs_idx]
    vm_args = ini_lines[vmargs_idx + 1 :]
    data_idx = launcher_args.index("-data")
    ws_arg = launcher_args[data_idx + 1]

    cases.append(
        check(
            "eclipse_ini_and_restart_args",
            "Verify eclipse.ini separates launcher arguments (-data) from -vmargs heap/encoding flags on restart",
            {
                "workspace_arg": "/workspace/java-ee",
                "vm_arg_count": 3,
                "has_utf8_encoding": True,
            },
            {
                "workspace_arg": ws_arg,
                "vm_arg_count": len(vm_args),
                "has_utf8_encoding": "-Dfile.encoding=UTF-8" in vm_args,
            },
        )
    )

    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
预期结果 · 待实际运行核验
  • 验证 `File > Restart` 保存脏文件并沿用原 `-data` 工作空间、激活安装后暂缓生效的插件,以及 `eclipse.ini` 启动参数与 `-vmargs` 分离解析。
运行 Eclipse File > Restart 状态保存、延迟插件激活与启动参数保留离线核验

所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

当前源码 SHA256:0907a499472700c49982b82af3e11e796a8719759fa8fe7f1eb657cd439f442d

下载本站示例源码

本地运行

解压后按 README 说明在对应本地环境运行脚本。

下载Eclipse 重启选项实验

所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

ZIP SHA256:c1364c217ddae5528cb932ee79a81b14c114dadbb77fa156ff4c04550063d5fb

常见错误与边界

  • 实际端口、文档资源与应用配置都应和测试条件一致。

练习与解答

在安装完 Eclipse 插件并选择“暂不重启”之后,后续如何最方便地重新启动当前工作空间使插件生效?

展开参考解答

保存当前改动后,直接点击顶部菜单 `File > Restart`,Eclipse 会自动关闭并沿用当前工作空间目录重新拉起进程,加载新安装的插件。

规范与官方依据