【问题标题】:Open file in Eclipse through URL handler通过 URL 处理程序在 Eclipse 中打开文件
【发布时间】:2014-04-14 11:30:30
【问题描述】:

在我的项目中,我有一个特殊的 JSP,它在出现异常时显示异常堆栈跟踪。

有没有办法使用 URL 处理程序或其他可以让 Eclipse 打开文件的方法?也许是xdg-open

我在 Kubuntu Linux 上使用 Eclipse 4.3。

【问题讨论】:

  • TeamCity 的插件以某种方式做到了这一点。我想您可以编写一个 Eclipse 插件,在端口 9998 上启动一个微型 Web 服务器,然后当您尝试加载 localhost:9998:///path/to/file.ext:66 之类的 url 时,它将发送一个虚拟响应,并将在 eclipse 中打开文件(也许它也可以激活窗口)。查看 play 的开发错误页面,该链接可能已将目标设置为隐藏的 iframe。

标签: java eclipse xdgutils


【解决方案1】:

我最终得到了这个解决方案:

  1. 编辑xdebug.ini(应该是/etc/php/7.0/mods-available/xdebug.ini之类的地方),添加:

    xdebug.file_link_format="xdebug://%f(%l)"
    

    重启你的服务器或 php-fpm。对于 Ubuntu 上的 Apache,请使用 sudo service apache2 restart

  2. 创建eclipse-launch.sh。它旨在解析 URL 并将文件传递给 Eclipse。你可以随意命名并放在任何你想要的地方,我已经把它放在了 ecrise 目录中。请务必将/home/user 替换为您的实际主目录,并将path="..." 替换为实际的eclipse 路径:

    #! /bin/bash
    
    arg=$1
    path="/home/user/eclipse/eclipse-neon/"
    
    # file name directly followed by a line number in parenthesis
    regex="//([^(]*)\(([0-9]+)\)"
    
    if [[ $arg =~ $regex ]]
    then
        file=${BASH_REMATCH[1]}
        line=${BASH_REMATCH[2]}
        $path/eclipse --launcher.openFile "$file"+"$line"
    else
        msg="Unsupported URL: $arg"
        zenity --info --text="$msg"
    
        # alternatives:
        # notify-send "$msg" # another notification program
        # $path/eclipse # just run eclipse
    fi
    

    在此处阅读有关 Eclipse 命令行选项的更多信息:http://help.eclipse.org/mars/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/product_open_file.htm

  3. 赋予文件可执行权限:chmod +a eclipse-launch.sh

  4. ~/.local/share/applications/ 创建xdebug.desktop。它将被xdg-open 使用(Chrome 默认使用 xdg-open)。

    [Desktop Entry]
    Comment=
    Exec=/home/user/eclipse/eclipse-neon/eclipse-launch.sh "%u"
    Icon=/home/user/eclipse/eclipse-neon/eclipse/icon.xpm
    Name=Eclipse xdebug Launch
    NoDisplay=false
    StartupNotify=true
    Terminal=0
    TerminalOptions=
    Type=Application
    MimeType=x-scheme-handler/xdebug;
    
  5. 运行xdg-mime default xdebug.desktop x-scheme-handler/xdebug。这应该将一个条目添加到~.local/share/applications/mimeapps.list[Default Applications] 部分。条目本身应类似于 x-scheme-handler/xdebug=xdebug.desktop

  6. 对于 Firefox,请遵循此处的说明:https://xdebug.org/docs/all_settings#file_link_format

    • 打开about:config
    • 添加新的布尔设置network.protocol-handler.expose.xdebug 并将其设置为false
    • 第一次单击 xdebug:/// 链接时,Firefox 会提示您选择要运行的应用程序,指向创建的 eclipse-launch.sh 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-06
    • 2012-10-17
    • 1970-01-01
    • 2013-04-12
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多