3

I have already a Java Project in Intellij.

I want to make a .exe Java file, but I did not find any solution yet for Java Projects. On the other hand, I have found many youtube videos in which they use a JavaFX Project to create an artifact which they will use to create a .exe file.

One of them is the following youtube video: IntelliJ export JavaFX application to exe on Windows

My end goal is, that a user just double clicks on the file and a GUI opens. After entering some information the rest of the code should run. The file should be able to run to different windows systems, so this should not only work when installing special packages.

Did I chose the wrong type of project? To that I just read, that JavaFX will be discontinued.

I am confused in so many levels...

Georgios
  • 861
  • 2
  • 12
  • 30
  • 4
    JavaFX is not being discontinued as of yet. It has simply been removed from the JDK—as of JavaFX 11—and is now developed/maintained as a separate project. – Slaw Mar 08 '19 at 21:45
  • So I now have found another way to do it. After creating a .jar file a can create a .bat file. In there I can write the following 'java -jar name.jar' then the program will run. I still would like to avoid the creation of a second .bat file. Is there perhaps another solution? – Georgios Mar 08 '19 at 21:57

2 Answers2

1

What you're looking for is an executable jar file I think. I know that eclipse you can generate one so I'd assume you can do the same in intellij. How to

HeftyDolphin
  • 53
  • 1
  • 12
  • I have already created an executable .jar file. Nevertheless, I have to create a .bat file containing (java -jar name.jar) to make it run. I just want to have one file, that starts with a double click. – Georgios Mar 08 '19 at 22:03
1

You should first make an executable .jar file and then use an .exe wrapper on the jar. I've used

Launch4j in the past with great success. I haven't tried it on javafx yet, but there are many executable wrappers to choose from with a quick google search. If this is at all unclear, leave a comment, and I'll detail these steps more. Launch4j has an almost self explanatory interface, so I don't think you should have trouble as long as you're sure your .jar launches.

geekTechnique
  • 850
  • 1
  • 11
  • 38
  • Before I get more into it, does this mean I need more than 1 file? – Georgios Mar 08 '19 at 22:08
  • 1
    No it does not. Executable wrappers make a single .exe file that contains your .jar and other asset files if you want. – geekTechnique Mar 08 '19 at 22:09
  • Lovely. I will search the web for more info, on how to implement it. – Georgios Mar 08 '19 at 22:11
  • No problem. If you find that this answers your question after you're done researching and attempting to implement the wrapper, that checkmark would help me out :) – geekTechnique Mar 08 '19 at 22:16
  • 1
    JavaFX is very much alive, run as an open-source project, [*OpenJFX*](https://openjfx.io/), hosted and led by the [Gluon](https://gluonhq.com/) company that sells tools and services for developing cross-platform mobile apps oriented to the enterprise. – Basil Bourque Mar 08 '19 at 22:39
  • @TerryDorsey I just watched a tutorial and created a .exe file from my code. When I double click on it, unfortunately, nothing happens. On the other hand, when I use the .bash file which contains the (java -jar name.jar) I can see the cmd opening and there i can type the info. I guess my code is missing something. I guess I have to write a GUI? – Georgios Mar 08 '19 at 22:56
  • @Georgios If you double-click on the exported .jar file, does it open your gui and run like it should? – geekTechnique Mar 08 '19 at 22:57
  • @TerryDorsey I do not have a GUI implemented yet. This is the next step that I have to make. When I double click my .jar file nothing happens. As already stated, if I use the cmd/Powershell or create a .bash file and type (java -jar name.jar) the code is running and I can interact and see my code in the cmd/Powershell. – Georgios Mar 08 '19 at 23:05
  • 1
    @Georgios If you don't have a GUI, then the .jar and .exe files should still run, but there will be nothing to see, as there is no console output showing. To say it another way, if your .jar writes to a file, that should still happen, but there will be no evidence of that happening unless you inspect the aforementioned file for what your program affected. If you would like to launch a cmd window or terminal programmatically from your java code, see this link. https://stackoverflow.com/questions/4688123/how-to-open-the-command-prompt-and-insert-commands-using-java – geekTechnique Mar 08 '19 at 23:19
  • @TerryDorsey You are right :) I just wrote a test GUI and it is working. Is it possible to have a GUI, where the user can write information and at the same time see logger info/ system output at the bottom of the window? So everything in just one window? – Georgios Mar 08 '19 at 23:24
  • 1
    @Georgios You can redirect the System output to a PrintStream and therefore, you can apply that to a JavaFX element or node, like a TextField, or Label. An example can be seen here: https://stackoverflow.com/questions/8708342/redirect-console-output-to-string-in-java – geekTechnique Mar 08 '19 at 23:32
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/189707/discussion-between-georgios-and-terry-dorsey). – Georgios Mar 08 '19 at 23:43