Skip to content

Instantly share code, notes, and snippets.

@Moddus
Created January 12, 2016 13:31
Show Gist options
  • Select an option

  • Save Moddus/f3daff49031fba6dfb1a to your computer and use it in GitHub Desktop.

Select an option

Save Moddus/f3daff49031fba6dfb1a to your computer and use it in GitHub Desktop.

Revisions

  1. Moddus created this gist Jan 12, 2016.
    17 changes: 17 additions & 0 deletions solr_test.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    public static File getFile(String name) {
    URL url = Thread.currentThread().getContextClassLoader().getResource(name.replace(File.separatorChar, '/'));
    if(url != null) {
    try {
    return new File(url.toURI());
    } catch (Exception var3) {
    throw new RuntimeException("Resource was found on classpath, but cannot be resolved to a normal file (maybe it is part of a JAR file): " + name);
    }
    } else {
    File file = new File(name);
    if(file.exists()) {
    return file;
    } else {
    throw new RuntimeException("Cannot find resource in classpath or in file-system (relative to CWD): " + name);
    }
    }
    }