2

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

Mattizin
  • 350
  • 1
  • 6
  • 19
  • why would you want to create an exe of a Java application? – Stultuske Mar 20 '18 at 13:35
  • 1
    Check this https://stackoverflow.com/questions/35656121/bundle-jre-with-install4j – Victor Gubin Mar 20 '18 at 13:38
  • @Stultuske i dont need an exe, but the only options to bundle my application to an JRE were with an exe beeing the entry point on windows – Mattizin Mar 20 '18 at 13:41
  • @VictorGubin thanks, i will look into that – Mattizin Mar 20 '18 at 13:41
  • As you're already using Maven, you can also look in to Shade Plugin or similar. Such plugins will also help you in packaging the whole application and you will also be able to run it using nothing but a command line and e.g `java -jar .jar`. Also, you can bundle this jar-file in a zip using the assemble-plugin if you need jre/jdk to be included as well. – vegaasen Mar 20 '18 at 13:55
  • @vegaasen the maven assembly plugin itself creates a executable jar with its dependencies inside fro me, which i can execute via command line with java -jar jarfile.jar, but i need a way to bundle this application with an JRE and release it together.... – Mattizin Mar 20 '18 at 16:08

1 Answers1

2

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.

toolforger
  • 754
  • 7
  • 22