-1

Problem

I created a Java project in Eclipse and intended to make an exe file that takes a xlsx file and a text file next to it. Is it possible?

Here's the directory structure of my project:

.
|-.settings
|- bin
|- src
|   |- MyApp.java
|   |- input.xlsx
|   |- key.txt
|
|- .classpath
|- .project

I also added external jar files such as Apache POI from my IDE (Eclipse). It runs with no errors in the IDE.

Desired Outcome

I want to create a exe file as follows:

.
|- MyApp.exe
|- input.xlsx
|- key.txt
|- log
|   |- error-mmddyyyy.txt

So when MyApp.exe is executed, it will take input.xlsx and key.txt as its input, and generate output in log directory. And I can send this exe file to someone else. If they structure the files correctly, the program will have correct input, and generate correct output. They don't need to install Java or anything else.

I wanted to know if this was achievable.

Solution Attempted

Launch4j

I have tried exporting the project into a runnable jar file, and I am able to run the file using java -jar MyApp.jar. I tried using Launch4j but I failed because of some version issues:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Test has been compiled
by a more recent version of the Java Runtime (class file version 61.0), this version of
the Java Runtime only recognizes class file versions up to 52.0

I tried to recompiled my program to Java 8 but it made my program not recognize the jar files I added.

jpackage

I also attempted to use jpackage to create an installer for Windows, but the outcome was not what I was looking for. This created an exe to "install" a program to the system. I only wanted an exe file to do what I programmed in the java project.

Thank you in advance for whoever leaves a comment or answer!

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Ariel
  • 11
  • 3
  • You can fix the "version issues" as per the duplicate Q&A. The very best and canonical solution however is to not even create an .exe file but rather use the jar. – Hovercraft Full Of Eels Aug 15 '23 at 23:58
  • Added a duplink on native executable building using GraalVM. The title says Windows, but GraalVM can generate Linux executables too. – Stephen C Aug 16 '23 at 01:16
  • Your exceptionally well-crafted question reveals you have a conceptual problem. You complain: *This created an exe to "install" a program to the system*, but this is precisely what you need. Your group of bound resources and executable *requires* an installer. Even a zip archive that would place those files on the target system would act as a crude (one that couldn't *un*install your project) installer. Since you don't need 3rd party tools and Launch4J (at a quick glance) seems to be stuck with an old VM, `jpackage` is precisely what you need to manage your software. Embrace it with relish ;) – g00se Aug 16 '23 at 07:30

0 Answers0