Java URI to Base getBaseURI()

Here you can find the source of getBaseURI()

Description

Get the Basedir for the project as a URI

License

Open Source License

Return

the URI for the project basedir

Declaration

public static URI getBaseURI() 

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.URI;

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

    /**//from   w  ww  .  j  a  v a2s. co m
     * Get the Basedir for the project as a URI
     * 
     * @return the URI for the project basedir
     */
    public static URI getBaseURI() {
        if (baseURI == null) {
            getBasedir();
        }
        return baseURI;
    }

    /**
     * Obtain a reference to the maven ${basedir} for the module.
     * <p>
     * Note: while running in maven, the ${basedir} is populated by maven and used by the surefire-plugin.
     * <br>
     * While running in eclipse, the ${basedir} property is unset, resulting in this method falling back to
     * ${user.dir} equivalent use.
     * 
     * @return the equivalent to the maven ${basedir} property.
     */
    public static File getBasedir() {
        if (basedir == null) {
            String cwd = System.getProperty("basedir");

            if (cwd == null) {
                cwd = System.getProperty("user.dir");
            }

            basedir = new File(cwd);
            baseURI = basedir.toURI();
        }

        return basedir;
    }
}

Related

  1. getBase(final URI uri)
  2. getBaseName(URI uri)
  3. getBaseURI()
  4. getBaseURI(final URI uri)