1

I've created a small Java application that uses GUI and a few of my friends who have Windows have asked me to send it to them. I want to avoid them as many steps as possible regarding installation, etc..., so I'm wondering which would be the best way.

So I built the .jar from NetBeans and when I run it it works perfectly. From there on I tried to generate a single portable .exe file for Windows that I could send them and they could just open without any previous step (provided they have a JRE). So I downloaded JSmooth, Jar2Exe and Launch4j and all of those generate a .exe file but as soon as I change it's location it doesn't work any longer, so I see no advantage in that over the .jar file.

So what I want to know is: is there any way of wrapping everything together into a .exe that would work always in Windows no matter where it is located?

In case it matters: the project uses the added library JLayer (for Mp3).

Thanks!

P.S.: I am a complete newbie to programming and computers in general so please be patient and take nothing for granted.

  • There are several exe wrappers available, I personally use exe4j, but's commercial, but at the time I needed it, was the only 64 bit wrapper available. You could also use one of the many installer packages, like izpack. Some even provide the ability to install the JVM as well, but I've fallen into the habit of including the JVM I want people to use embedded with my program ;) – MadProgrammer Aug 08 '15 at 03:09
  • 1
    " but as soon as I change it's location it doesn't work any longer, " - no they do work- you missed something else. Not clear from question though.. – Jayan Aug 08 '15 at 03:14
  • I mean that when I run the generated .exe file from the folder it's created in initially, it works, but as soon as I change it's location (for example, by copying it to another folder or dragging it to the desktop) I click on the icon and nothing happens, the .exe doesn't launch the application. I hope it is clear now. Maybe I'm missing setting something in the options of the exe wrappers before generating the exe file. – Otto Helmut Bungelmann Aug 08 '15 at 04:00
  • Does the jar depend on files in the folder? Moving its location could cause it to fail to find the files, which without absolute paths are specified as being in the directory of the jar. – D. Ben Knoble Aug 08 '15 at 04:08
  • I think the issue where the application can't run when it is transferred to another location is not on the wrapper itself. It is on the settings if one uses an absolute path or relative path. – d_air Aug 08 '15 at 04:10
  • Yes, @BenKnoble, on the same folder as the jar file (/dist) there's a folder with the libraries (/lib), so it seems I wasn't succesful in packing my external libraries into the .jar file with NetBeans. I'll try to do that and then try again with the wrapper, thanks! – Otto Helmut Bungelmann Aug 08 '15 at 04:22
  • @d_air I'm only using relative paths. – Otto Helmut Bungelmann Aug 08 '15 at 04:25
  • BTW if someone could tell me how to pack/extract external libraries into a jar file with NetBeans I would be very grateful. – Otto Helmut Bungelmann Aug 08 '15 at 04:32
  • yes, I believe that's only one requirement. In my application, I don't transfer only the executable file. I copy the entire folder so the structures of the files needed on my application won't be broken. If I send my application to someone, I zip the whole folder, and then send it. As long as the receiver will not break the structures in my folder, my application runs fine. I also see to it that my app won't depend on external libraries as much as possible. – d_air Aug 08 '15 at 04:34
  • @OttoHelmutBungelmann, Please ask a separate question about packing libraries in netbeans. I believe there are people who are willing to answer that including myself. – d_air Aug 08 '15 at 04:37
  • Thanks for your previous answers, @d_air. I think I'll try the way you do it. Ok, I'll ask a new question about that in a few minutes if I don't find a previous similar question.. – Otto Helmut Bungelmann Aug 08 '15 at 04:41

2 Answers2

1

You can use Launch4j. In my application, I just create a launcher. It is a small .exe file to launch the jar file. In that way, I don't have to create .exe file every time I have a new jar file. I just rename the jar file so that it matches what is set in the .exe file. I place the exe and jar files in the same folder. As long as the jar execution has no problem with the dependencies and libraries, running the exe file shall also have no issues.

d_air
  • 631
  • 1
  • 4
  • 12
  • That's what I think my wrappers are doing for me, because as soon as I place the .exe and the .jar in separate folders the .exe cannot launch the application any longer. But it's not just that: now that you mention it, on the same folder as the jar file (/dist) there's a folder with the libraries (/lib), so it seems I wasn't succesful in packing my external libraries in the .jar file with the IDE. I'll try again once I do that. Thanks! – Otto Helmut Bungelmann Aug 08 '15 at 04:14
0

Firstly, make sure that you bundled all external libraries and external links(image path,file path etc.) into your .jar file because as soon as you move .jar file from your project folder it can't access external links anymore.

Here is the question that can help you figure out how to do it: How to bundle images in jar file After that your .jar is ready for export.

PS: be careful when you embedding external libraries in case they are proprietary

Bane2000
  • 187
  • 1
  • 9