4

In my project, I have a special JSP which displays the exception stacktrace in case of Exceptions.

Is there a way to use an URL handler or something else which would have Eclipse open a file? Maybe with xdg-open?

I use Eclipse 4.3 on Kubuntu Linux.

yglodt
  • 13,807
  • 14
  • 91
  • 127
  • TeamCity's plugin does this somehow. I suppose you could write an eclipse plugin that starts a miniature web server say on port 9998, then when you try to load a url like localhost:9998:///path/to/file.ext:66 it will send a dummy response, and will open the file in eclipse (maybe it could also active the window). Looking at play's dev error page, the link could have target set to a hidden iframe. – nafg Dec 25 '14 at 20:19

1 Answers1

2

I've ended up with this solution:

  1. Edit xdebug.ini (it should be somewhere like /etc/php/7.0/mods-available/xdebug.ini), add:

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

    Restart your server or php-fpm. For Apache on Ubuntu use sudo service apache2 restart.

  2. Create eclipse-launch.sh. It is intended to parse URL and pass a file to Eclipse. You can name it as you want and put it anywhere you want, I've placed it in the eclise directory. Be sure to replace /home/user with your actual home directory and path="..." with actual eclipse path:

    #! /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
    

    Read more about Eclipse command line options here: http://help.eclipse.org/mars/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/product_open_file.htm

  3. Give the file executable permissions: chmod +a eclipse-launch.sh

  4. Create xdebug.desktop at ~/.local/share/applications/. It will be used by xdg-open (Chrome uses xdg-open by default).

    [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. Run xdg-mime default xdebug.desktop x-scheme-handler/xdebug. This should add an entry to ~.local/share/applications/mimeapps.list to [Default Applications] section. The entry itself should look like x-scheme-handler/xdebug=xdebug.desktop

  6. For Firefox follow instructions from here: https://xdebug.org/docs/all_settings#file_link_format

    • Open about:config
    • Add a new boolean setting network.protocol-handler.expose.xdebug and set it to false
    • The first time you click on xdebug:/// link Firefox will prompt you to select an application to run, point to the created eclipse-launch.sh file.
zyura
  • 21
  • 3