1

I’m trying to make an EXE file from my Java application using the exe4j tool. I have successfully built the project JAR file as well as the lib directory. I have created the EXE and its working smoothly. I am creating barcodes & profile photos in my application. This is how I set my path

  • Saving Image

     File outputfile = new File("./src/com/ntap/solution/jmsystem/profilePics/"     + formId + ".jpg");
            if (outputfile == null) {
                outputfile.createNewFile();
            }
    
            boolean write = ImageIO.write(icon, "jpg", outputfile);
    
  • loading image...

     url = "/com/ntap/solution/jmsystem/profilePics/" + formID.getText() + ".jpg";
        ImageIcon icon = new ImageIcon(getClass().getResource(url));
    

But after converting to the EXE, the image file path doesn't load from where it should load. error appears File Could not found

This process works perfectly with the JAR and also the Project. Are there any concepts I should know before settings paths like this that could be a problem in the exe?

Should I save the images on external location? like C:/documents/.. How do I go about doing this?

Asela Wijesinghe
  • 157
  • 2
  • 13
  • Welcome to Stack Overflow! Our community expects you to try to use proper formatting and spelling. If you haven't, go through the [tour](http://stackoverflow.com/tour). –  Dec 31 '15 at 20:43
  • Your `url` starts with a slash, indicating a full path; unless your jar file contains the full path to the image that way, the runtime isn't going to find the image there. Make a relative path to your image; the standard way is to put the image either in the directory with the class that loads it, or in a subdirectory of that named "images". In the latter case the URL to load the image would be "images/" + blahblah + ".jpg", in the former just leave off the "images/". – arcy Dec 31 '15 at 21:20
  • You can't save images to src, it doesn't exist at runtime. If the files are stored in the src directory, then building the project into a jar should include the images, depending on the build process – MadProgrammer Dec 31 '15 at 21:44
  • If recommend starting by using System.getProperty("user.home") and creating a sub directory for your program (convention would have you put it in the AppData directory) – MadProgrammer Dec 31 '15 at 21:46
  • @arcy Thank you very much for your knowledge and the suggestions!! – Asela Wijesinghe Dec 31 '15 at 21:48
  • @madProgrammer yes, now i have a clear idea thanks to all of your comments – Asela Wijesinghe Dec 31 '15 at 21:53

0 Answers0