URI Scheme: Endless Command Prompts Open

I went through the following doc center and tried to create my own URI scheme myDocs: https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx

The following is my Java program. It takes a command line argument and returns the URL in the browser.

import java.awt.Desktop;
import java.io.IOException;

public class URIOpen {
    public static void main(String args[]) {
        if (args.length == 0) {
            return;
        }

        String uri = args[0];

        try {
            Desktop.getDesktop().browse(java.net.URI.create(uri));
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

I updated the default value field for the command key as shown below.

"C:\Program Files (x86)\Java\jdk1.8.0_102\bin\java" -cp "C:\Users\Krishna\Documents\Study\Miscellaneous\examples"  "URIOpen" "%1"

When I try to run a command myDocs:http://google.com, I end up opening endless command lines.

The structure of the URI scheme schema entry in the registry is as follows. Any help on this?

enter image description here

+4
source share
1 answer

-:

  • URIOpen, , myDocs: URI;
  • URIOpen Desktop.getDesktop().browse(java.net.URI.create(uri));, URI (myDocs:), ...

, :

    try {
        java.net.URI theURI = java.net.URI.create(uri);
        // System.out.println(theURI.getScheme()); => myDocs
        String uriBrowsablePart = theURI.getRawSchemeSpecificPart();
        // System.out.println(uriBrowsablePart); => http://google.com
        Desktop.getDesktop().browse(java.net.URI.create(uriBrowsablePart));
        // the above statement will open default browser on http://google.com
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }

try-catch , .

+2

Source: https://habr.com/ru/post/1658834/


All Articles