Project

General

Profile

How to get File from Resources in plugin

Razor Ra
Added about 5 years ago

Hi,

I have created a tigase plugin in Maven, and place the jar inside tigase lib folder.

My project directory structure is:

my-app
      src
         main|
             |
             |--java|
             |      |
             |      TestPlugin.java
             |
             |--resources|
                         |
                         |--test|
                                |--hello.txt

I have tried getting it through various methods, I have tried getting it through getResourceAsStream(...) and some other ways.

But I am not been able to get it.

String path = this.getClass().getResource("/test/hello.txt").getFile();
File file = new File(path);
System.out.println(path);
System.out.println(file.exists());

I always get this output, no matter what method I adopt:

/home/razor/Tigase-5.1.5/file:/home/razor/Projects/Tigase/TestPlugin/target/TestPlugin-1.0.jar!/test/hello.txt

false