Created
May 7, 2014 19:26
-
-
Save buren/2767c6665af7919926f6 to your computer and use it in GitHub Desktop.
Simple Java Singelton Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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