You can put assets inside your jar.
For example, if you have a file called Test.txt and you want to print
the file content to the console
The "Test.txt" file is placed into a package called assets at the same level of the root package
The project structure will look like this
package net.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Test {
public static void main(String[]args) {
BufferedReader br = null;
try {
InputStream is = Test.class.getResourceAsStream("/assets/Test.txt");
if(is != null) {
br = new BufferedReader(new InputStreamReader(is));
//Print the content of Test.txt
String line;
while((line = br.readLine()) != null) {
System.out.println(line);
}
} else {
//Resource not found
System.out.println("Resource unavailable!");
}
} catch (IOException e) {
e.printStackTrace(); //Log IO Error
} finally {
if(br != null) {
try {
br.close();
} catch (IOException e) {}
}
}
}
}
You cannot access .jar resources as you normally do with external files by using a File object.
If your assets are into the jar, you can then use Launch4j (or alternative) to
get an .exe.