Java Path to URL toTargetURL(String path)

Here you can find the source of toTargetURL(String path)

Description

to Target URL

License

Open Source License

Declaration

public static URL toTargetURL(String path) throws MalformedURLException 

Method Source Code


//package com.java2s;
// are made available under the terms of the Eclipse Public License v1.0

import java.io.File;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

public class Main {
    private static File basedir;
    private static URI baseURI;

    public static URL toTargetURL(String path) throws MalformedURLException {
        return getBaseURI().resolve("target/" + path).toURL();
    }/*from  w  w  w. j a v a  2 s.c o m*/

    public static URI getBaseURI() {
        if (baseURI == null) {
            getBasedir();
        }
        return baseURI;
    }

    public static File getBasedir() {
        if (basedir == null) {
            String cwd = System.getProperty("basedir");

            if (cwd == null) {
                // System property not set.

                // Use CWD.
                cwd = System.getProperty("user.dir");
                basedir = new File(cwd);

                // Set the System property.
                System.setProperty("basedir", basedir.getAbsolutePath());
            } else {
                // Has system property, use it.
                basedir = new File(cwd);
            }

            baseURI = basedir.toURI();
        }

        return basedir;
    }
}

Related

  1. pathsToURLs(ClassLoader classLoader, String... paths)
  2. pathToUrl(String path)
  3. pathToURL(String path)
  4. pathToURLs(String path)
  5. pathToURLs(String path)
  6. toUrl(final String path)
  7. toURL(String path)
  8. toURL(String pathPrefix, String jar)
  9. toURLs(String... paths)