Search code examples
javaurleclipse-pluginrelative-path

Eclipse Welcome-page plugin: How to open relative path on external browser from Intro.xml


How can to open a url on external browser using a relative path from a customized Eclipse Welcome page plugin?

The following code is an example of what I have so far from the intro.xml, which is working OK for Linux but doesn't work for Windows.

             <link 
                label="Documentation" 
                url="http://org.eclipse.ui.intro/openBrowser?url=file:../documentation/index.html"   
                id="link-img-documentation" 
                style-id="content-link">
              <text>Read documentation.</text>
             </link> 

Solution

  • One alternative way is to use http://org.eclipse.ui.intro/runAction and create a class that implements IIntroAction Overall, you will need to do two things.

    • Add a class that implements IIntroAction
    public class OpenFileInBrowser implements IIntroAction {
        @Override
        public void run(IIntroSite site, Properties params) {
            
            if (params.containsKey("filePath") ){
                String filePath = params.getProperty("filePath");
                String workingDir = System.getProperty("user.dir");
                String urlString = "file://" + workingDir + File.separator + filePath;
                
                try {
                    IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
                    IWebBrowser browser = browserSupport.getExternalBrowser();
                    URL url = new URL(urlString);
                    browser.openURL(url);
                } catch (Exception e) {
                }   
            }   
        }
    }
    
    
    • Update url in the link tag as following:
     url="http://org.eclipse.ui.intro/runAction?pluginId=x.y.z&amp;class=x.y.z.OpenFileInBrowser&amp;filePath=../documentation/index.html"