I'm using Launch4j to create a exe file for my code. The exe file created successfully but because I use in my code some images into GUI, the exe file doesn't work. How can I insert my images into the exe file? Thanx
-
1Have you tried running the JAR file before making an EXE? Are you sure the images are to blame here? – Ceiling Gecko Dec 19 '13 at 09:25
-
Yes, I tried to run jar file before and the problem is same. – Ibrahim Dec 19 '13 at 09:28
-
1@Ibrahim then it has **nothing to do with Launch4J**. – Moritz Petersen Dec 19 '13 at 09:29
1 Answers
My projects usually have a folder structure like this:
/src
/main
/java
/resources
/test
...
(because I use Maven; Launch4J has a good Maven plugin, btw.).
I put all images, that need to be available for the application, into the /resources
folder.
During the build process, images are copied into the output folder, where all the compiled .class
files are. The images are now in the classpath.
To access resources (i.e. images) in your classpath, you can use the classloader, such as:
Resources in the root directory (
src/main/resources/image.jpg
) can be accessed through the System ClassLoader:ClassLoader.getSystemResource("image.jpg"); ClassLoader.getSystemResourceAsStream("image.jpg");
Resources in other packages (e.g. for
com.example.MyClass
the resource should be atsrc/main/resources/com/example/image.jpg
) can be accessed through the class itself:MyClass.class.getClassLoader().getResource("image.jpg");
Launch4J never complains about that and uses the images without any problem, even in .exe files.

- 12,902
- 3
- 38
- 45
-
That work perfect. One more question, if you need to run your app in another computer, what path file you put for you images into your code? – Ibrahim Dec 19 '13 at 10:45
-