1

I want to create a windows installer for my jar file. I don't want to have to install jre/jdk on the target computer I want to deploy to.

I tried out jpackage (part of Java 14) and it didn't work for me. I tried the following command:

jpackage --input target/ --name my_pkg --main-jar NtbnsProj.jar --main-class myJFrame --type exe --java-options '--enable-preview'

It generates a my_pkg-1.0.exe, but I can't get it to run.

At this point, I'm willing to try even third party tools. I've tried install4j with no success. Another website I found said to use install4j with Inno Setup Compiler. This was more complicated and didn't work either. I thought maybe WiX Toolset might work.

If someone could provide step by step instructions, especially if the solution involves install4j, as there are many different steps where you can miss something. I was using a newer version of install4j, and it didn't match the online tutorials and videos. The menu selections have changed significantly. Perhaps I need to use an older version of install4j.

See my related article: How do I package a java jar file to run on a Mac without JRE installed?

macdays
  • 63
  • 6
  • Well, my suggestion would be `jpackage`. You say the generated image doesn't run though. Have you tried debugging the problem? If it helps the tool has a [user guide](https://docs.oracle.com/en/java/javase/15/jpackage/packaging-overview.html#GUID-C1027043-587D-418D-8188-EF8F44A4C06A). – Slaw Nov 28 '20 at 06:31
  • The link you (@Slaw) provided, says that WiX 3.0 is required, but I don't see how I'm supposed to use WiX with jpackage. – macdays Nov 28 '20 at 06:37
  • As I understand it, WiX is only required on Windows. Your question indicates you're trying to create a package for a Mac. But if you are on Windows then you need only install WiX and then `jpackage` will find it on its own. And note that `jpackage` can only build a package for the operating system it's invoked on (e.g. if you're on Windows you can't build a Mac package). – Slaw Nov 28 '20 at 06:45
  • When I run the following command, ```jpackage --name myTest --input . --main-jar NtbnsProj.jar --jlink-options --bind-services``` I get the following error: "Error: Invalid Option: [--jlink-options]" – macdays Nov 28 '20 at 06:46
  • So I guess jpackage is invoking WiX, since I'm getting an .exe file. @Slaw, you are correct. I can't build a Mac application on a Windows computer. Although the linked (original) post was regarding building a Mac package, right now I'm just trying to build a Windows package on a Windows computer. – macdays Nov 28 '20 at 06:52
  • I've found that jpackage runs very well on Windows. You've not put enough info into this (or your other question) on what "I can't get it to run" means - list the actions / error messages. eg. does the installer exe and add to Windows Apps? Use`--win-console` to see the Java error messages if you have Program Files exe. – DuncG Nov 28 '20 at 11:10

2 Answers2

1

Double check that your app runs directly then fix any issues before continuing:

java -cp NtbnsProj.jar myJFrame 

It looks as though jpackage has worked, and generated your installer my_pkg-1.0.exe. When you run my_pkg-1.0.exe check that you have this file, then run it:

C:\Program Files\my_pkg\my_pkg.exe

If that fails, re-run jpackage with extra arguments --win-console --app-version 1.1, this will generate my_pkg-1.1.exe with console enabled. Re-install and running C:\Program Files\my_pkg\my_pkg.exe might report a useful error message indicating what is your real issue.

If you don't upgrade the --app-version each time, Windows will NOT update the existing release 1.0, or you must un-install before re-applying a re-build of same version my_pkg-1.0.exe. It just runs and stops without warning you.

See this post on how to set app-ver automatically.

DuncG
  • 12,137
  • 2
  • 21
  • 33
0

I got it to work! @DuncG was very helpful with answering my question. I had a bunch of extra files in the directory where the jar file was, so I just created a new directory and only put NtbnsProj.jar in it. I then ran the following command: jpackage --name Test --input . --main-jar NtbnsProj.jar

macdays
  • 63
  • 6