Mattizin
Mattizin

Reputation: 370

Java (Maven) Console Application. How to bundle it with an JRE?

i developed a java console application with the help of maven for my dependency management. The application is a pure console application, which means the user has to call it via the comandline and has to give parameters with it. I need to bundle the finiheD jar (with dependencies produced by maven-assembly-plugin) with an complete JRE, because the application has to be able to work on machines without java pre installed.

I tried to use the java packager -deploy command on the finished jar, but it doesnt really work: https://docs.oracle.com/javase/9/tools/javapackager.htm#JSWOR719

C:\jdk-9.0.4\bin>javapackager.exe -deploy -srcdir C:\folderwithjarinside -outdir C:\outdir -name Toolname -native -appclass [..].core.Main

After that i get a bundle with the jar, the complete jre and an exe to start the whole thing: enter image description here

When i now start the exe nothing happens and when i start it from an command line again nothing happens and i dont even get console output which SHOULD happen. When i start the jar allone i get console output even when i dont give parameters and it crashes cause of it.

How do i package my java console application with the JRE and are still able to start it as commandline application provide arguments and see console output?

Thanks in advance

Upvotes: 2

Views: 3418

Answers (1)

toolforger
toolforger

Reputation: 842

Multiple tools exist for packaging the JRE with your application:

  • install4j
    If you need a specific JRE, you will need access to the target platform, install the JRE there, and call a tool to package it. I recommend to do this just once, push the resulting JRE bundle as a non-Maven artifact to your repository, and use maven-download-plugin to pull it into your installer build.
    I can testify that EJ Technologies has great support, typical duration from question to answer is 24-48 hours, depending on how many follow-up questions you have, and I have yet to see a case where their answer was incomplete, mistaken, or misleading.
  • launch4j (see https://stackoverflow.com/a/7582064/6944068)
    I just know that it exists, I never tried it.
  • The JDK actually comes with a way to do that since 1.7
    Rumour has it that is badly designed and frustrating to use, but I don't really know.

I am pretty sure that neither launch4j nor the JDK support cross-platform builds for the installer, i.e. in your deployment toolchain, you need a machine with each target OS for each platform that you wish to have an installer for.
install4j isn't ideal in this respect, but at least you need the other-platform machines just once to create the JRE bundle.

Upvotes: 2

Related Questions