Skip to content

Commit

Permalink
Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gurpreet- committed Aug 24, 2019
1 parent 9360273 commit e0642e6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
# Resource Loader

Resource Loader gives you the functions to load `resource` files easily inside JARs or outside. Resource Loader also supports loading shared libraries.
Resource Loader gives you the functions to load `resource` files even if you are loading from inside a JARs or outside a JAR. Resource Loader also supports loading shared libraries through `SharedLibraryLoader`.

<a href='https://semaphoreci.com/libly/resource-loader'> <img src='https://semaphoreci.com/api/v1/libly/resource-loader/branches/master/badge.svg' alt='Build Status'></a>


### The problem

## Installation

Resource Loader is only available via Jitpack at the moment. Maven and SBT installation instructions available [here](https://jitpack.io/).

```groovy
// Top-level build.gradle
repositories {
// ...
maven { url 'https://jitpack.io' } // Add this line
}
dependencies {
// ...
implementation 'com.github.libly:resource-loader:1.1.3' // Add this line
}
```

## Usage

### Loading a file

Let's say you have a file in your `resources` folder called `test1.txt`. To get it you simply do the following:

```java
FileLoader fileLoader = new FileLoader();
File file = fileLoader.load("test1.txt");
```

Resource Loader can also load from paths and directories. Just make sure the top level directory name is somewhat unique:

```java
// The following loads test1.txt from the resources folder
// even if you supply a nested path.
File file2 = fileLoader.load("a_unique_top_level_folder/path/test1.txt");

// You can even load whole directories.
File dir = fileLoader.load("a_unique_top_level_folder/directory");
```

## What problem does Resource Loader solve?
Consider the scenario. You have a project with some files in the `resource` folder. You're loading those files using `getResourceAsStream` and it's working when you test it locally. But when you go to package the project as a JAR and then run it, it fails!

### The solution
Resource Loader provides developers with a fool-proof way of loading files inside or outside JARs and works with shared libraries (`.dll`, `.so`, `.dylib`). Scouring the Internet to piece together a solution was a labour intensive task with many quirks and pitfalls to look out for. So we thought why not package our solution and provide it in a reusable form.
Resource Loader provides developers with a fool-proof way of loading files inside or outside JARs by loading the files in a temporary folder that gets deleted when the process closes.

Resource Loader works with shared libraries (`.dll`, `.so`, `.dylib`). Scouring the Internet to piece together a solution was a labour intensive task with many quirks and pitfalls to look out for. So we thought why not package our solution and provide it in a reusable form.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
ext {
artifactId = "resource-loader"
groupId = "co.libly"
version = '1.1.2'
version = '1.1.3'
description = "Resource Loader gives you the functions to load resource files inside JARs or outside."
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/co/libly/resourceloader/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
Expand All @@ -19,15 +18,15 @@ public class Main {


public static void main(String[] args) {
System.out.println("Running.");
System.out.println("Running Resource Loader.");
FileLoader fileLoader = new FileLoader();
try {
File f = fileLoader.load("file1.txt");
if (f.isFile()) {
List<String> content = Files.readAllLines(f.toPath(), StandardCharsets.UTF_8);
System.out.println(content.get(0));
}
} catch (IOException | URISyntaxException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
Expand Down

0 comments on commit e0642e6

Please sign in to comment.