There is a code which then will be compiled in Jar.

There are resources that this code uses through the R. folder . file_name .

How do you need to rewrite the code (replace R. folder . File_name ) so that it automatically picks up the resource files that are in the same jar-e code?



    2 answers 2

    getClass().getClassLoader().getResource("tt/img/update.png") 

    tt folder - is in the root of the jar archive

    • And if resources - localization files. Is there a simple solution with them? - linya
    • yes no difference. In getResource insert the path to your localization files and give it to your method that will be responsible for localization, read it and so on. - G1yyK

    Try using ClassLoader:

    InputStream inStream = MyClass.class.getClassLoader (). GetResourceAsStream (nameResource);

    Accordingly, the nameResource should lie at the root of the jar file.