Skip to content

Instantly share code, notes, and snippets.

@buren
Created May 7, 2014 19:26
Show Gist options
  • Save buren/2767c6665af7919926f6 to your computer and use it in GitHub Desktop.
Save buren/2767c6665af7919926f6 to your computer and use it in GitHub Desktop.
Simple Java Singelton Example
package utils;
import java.net.URL;
public class Enduro {
private static Enduro ourInstance = new Enduro();
public static Enduro getInstance() {
return ourInstance;
}
private Enduro() {
}
/**
* Get path relative to root.
*
* @param relativePath the relative path to get (Starting at src/test/resources).
* @return the absolute path to resource.
*/
public String getResourcePath(String relativePath) {
URL resourceUrl = Enduro.getInstance().getClass().getResource("../");
return resourceUrl.getPath() + relativePath;
}
}
/*
USAGE:
Enduro enduro = Enduro.getInstance();
enduro.getResourcePath('app/');
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment