The shortest instructions. We are writing a simple test application, say "Hi Amigo!" to the HiAmigo.txt file 100 times.
public class Main {
public static void main(String[] args) throws IOException {
File file = new File("C:\\temp\\HiAmigo.txt");
FileWriter fileWriter = new FileWriter(file);
for (int i = 0; i < 100 ; i++) {
fileWriter.write("Hi Amigo! \n");
}
fileWriter.close();
}
}
We check that everything works at this stage (this is important!) Go to File -> Project Structure -> Artifacts -> + JAR -> From Modules with dependencies.. Specify the path to our Main.class: Click OK Click Build Artifacts - > Action - > Build Our artifact appears: We delete our test file “C:\\temp\\HiAmigo.txt” and run the JAR. The file should appear again. If it appears, everything is ok. Let's move on. Download the tool from the site https://launch4j.sourceforge.net/ (I recommend version 3.14, I’ll explain why later). Install and launch. We need two fields. We indicate our JAR and where to put the finished .exe. Now comes the most interesting part. Imagine a situation where the machine where we plan to use our application does not have the JRE installed and there is no way to install it. This often happens for security reasons. In addition, it would be nice to provide our application with a higher level of autonomy. Let's do the following. Let's create a separate directory for our application, let's say OurApp. Inside we create a JRE folder. Download the JRE (in my example, let it be jre-8u361-windows-i586), install it somewhere (if it’s a ready-made archive, unzip it) and extract all the files from it. We copy everything into \OurApp\JRE\ it should look something like this: In Launch4j, go to the JRE tab and in the Bundled JRE paths field: specify the name of the JRE directory Click on the gear and select any file to save the configuration like file.xml After clicking on save, ours will appear exe. Copy the exe and place it next to the JRE folder. Delete the test C:\temp\HiAmigo.txt. We launch the exe and watch how a new one is created. That's all. Now the OurApp directory can be archived and transferred anywhere, the exe will work. Important: The JRE version in the folder must be no lower than the one on which the artifact was built. Check the field: In my case, there were compatibility problems with the x86 platform and I used wrapper version 3.14, since it allows you to explicitly specify the type of target architecture. In general, thank you all for your attention. This was my first instructional article, please do not judge strictly. Peace for everyone!
GO TO FULL VERSION