Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.