How to run Java applications (.jar) without installing JDK - JRE on the computer?

3

Good afternoon, it happens that I made a Java application that uses external .jar for reports and other functions of the application. Also use SQLite. NetBeans by default creates a folder called 'dist' that contains the executable nameapp.jar; and the 'lib' folder where the libraries that the application needs are. The application I want to leave it in such a way that any user can download it in .exe format, install it (next-next-next- like any program) and create a shortcut on the desktop. I understand that with InnoSetup you can create installers, and to make the application work without the computer having Java installed, you have to copy the entire JRE folder of our Java where we compile etc .. Keep in mind that when you find a .jar file, and Java is not installed on the computer, then that icon will be in the Winrar, finally .. I hope you can help me, THANK YOU!

    
asked by Nelson Sepulveda 29.01.2018 в 00:05
source

2 answers

5

To use applications Java (jar) on different computers there are two ways:

  • Install the JRE (java) on each computer globally (the most common) or
  • Using a portable JRE package (such as jPortable ) within a Windows installation project.

For the second case it is necessary to take into account some things:

  • Have the portable package unzipped and located the java.exe file
  • Have a program to create Windows installation projects ( Smart Install Maker )
  • Generate a system instruction file (.bat or .cmd) to run the jar file.
  • Save ALL files within an installation project that will generate an .exe installer

Here is an example of the directory tree:

Tuapp/
├── Java Portable
│   └── bin
│       └── java.exe
├── libs
├── Tuapp.bat
└── TuJAR.jar

To run your jar, you must tell the system the path of the portable java and the path of your jar and save it in a .bat file, for example:

@echo off
"%cd%\JavaPortable\bin\java.exe" -jar "TuJAR.jar"

With that and if you pass all your folder to another computer, you can run the file Tuapp.bat to run your java application.

If you want to add an icon you must convert the .bat to an EXE ( Bat2Exe ) and generate the installer pointing to that EXE within the project of the installation creator.

    
answered by 29.01.2018 / 01:22
source
0

You could use jPortable to do what you're looking for: jPortable .

Please note that if we only talk about executing it is not necessary the JDK (Java Develoment Kit), since the person in charge of the execution is the JRE.

    
answered by 29.01.2018 в 00:34