Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the content of the jar during runtime?

Tags:

java

How can I access the content of the jar file which has been started. I want to create a big jar file which contains everything I need and then during runtime I want to copy some files of my jar into an external folder. Is this possible?

like image 892
Al Phaba Avatar asked Dec 18 '25 20:12

Al Phaba


1 Answers

You want this.getClass().getClassLoader().getResourceAsStream. Example:

InputStream config =
    this.getClass().getClassLoader().getResourceAsStream("config.txt");
like image 87
thejh Avatar answered Dec 21 '25 13:12

thejh