• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

! .exe application not working and can't figure out why

 
Ranch Foreman
Posts: 264
6
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

My problem of the day is as follows, I created a small application that compiles and builds perfectly in my Eclipse IDE, however once I wrapped it into an executable file it is not working and I cannot figure out why. I followed the instructions in this tutorial to the letter
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really need more information than you have provided to be able to help.  
What version of Java would be helpful.
Is it a GUI application and if so are you using Swing or JavaFX?  
When you try running the application are you doing so on the same machine used to develop the application?
When you package up the JAR can you still run the application?  
I also have an article on how to wrap a Java application into an exe using Launch4J.  This is using an older version of JDK (pre Java 9) and I think it is for a SWING based application.  You might like to take a look to see if it shines a light on something you missed in the article you are working through.  Here is the link: https://softwarepulse.co.uk/blog/wrap-java-into-an-executable-with-launch4j-part-2/
If you provide some more details I'm happy to try and help.
Regards,
John
 
Saloon Keeper
Posts: 13886
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On top of the excellent points that John has made, the most important thing you didn't tell us was how you know it doesn't work. ItDoesntWorkIsUseless.

I want to point out that a common reason that applications don't work when running them outside of your IDE is that you might be using file paths to reference resources such as images. Static resources should be embedded into your application, not referenced as if they were separate files.
 
Yosuf Ibrahim
Ranch Foreman
Posts: 264
6
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, sorry this is the first time I am wrapping up an application so I had no idea how to post my problem , so to answer your queries as follows:
  • I am using Java 17
  • It is a Java FX Application
  • I was trying to launch on the same machine I developed it on
  • The JAR application was not launching either


  • Stephan van Hulst wrote: On top of the excellent points that John has made, the most important thing you didn't tell us was how you know it doesn't work. ItDoesntWorkIsUseless.

    By it won't work I mean it would not launch when I try to open the Jar or the Exe nothing happens, a dialog which takes in a user name and password from the user should appear but it simply does not.

    Stephan van Hulst wrote: I want to point out that a common reason that applications don't work when running them outside of your IDE is that you might be using file paths to reference resources such as images. Static resources should be embedded into your application, not referenced as if they were separate files.



    The application icon is the only image and it is embedded into the application and not referenced

     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Please tell us how you're executing the JAR. Are you simply double-clicking it? That won't work if the JAR is not executable.

    Run the following command on the JAR and tell us if there's any output:
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Please tell us how you're executing the JAR. Are you simply double-clicking it? That won't work if the JAR is not executable.

    Run the following command on the JAR and tell us if there's any output:



    I know this is going to be the dumbest question in java history and I will be made fun of for decades for asking this question, but how am I supposed to do that?
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Open a command line prompt in your operating system, navigate to the folder that contains the JAR, and then type the command that I gave you, replacing "jarname.jar" with the actual name of your JAR.

    On Windows, you can very easily open a command prompt in the correct location by browsing into the folder where you want to open the command line prompt, and then typing "cmd" in the address bar of the explorer window and hitting enter.
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Open a command line prompt in your operating system, navigate to the folder that contains the JAR, and then type the command that I gave you, replacing "jarname.jar" with the actual name of your JAR.

    Got it, thank you

    Here is what I get
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Inside a JAR file is a manifest file that contains metadata about the JAR. One of the entries that you (or rather, your build tool) can add to the manifest is the name of the main class that needs to be run when the JAR is executed. Without this entry, you must supply the name of the main class to run each time you run the java command, and obviously that also means you can't run the JAR by double clicking on it.

    So, to make your JAR executable you need to tell your build tool to add this entry to the manifest. The easiest way to do this depends on your build tool. Are you using Maven? Are you just relying on your IDE? What IDE are you using?
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:
    So, to make your JAR executable you need to tell your build tool to add this entry to the manifest. The easiest way to do this depends on your build tool. Are you using Maven? Are you just relying on your IDE? What IDE are you using?

    I as just relying on my IDE to do it it, it is eclipse 2021-12
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Does your project contain a pom.xml file? It's the project descriptor for a Maven build, which I'm sure Eclipse can handle these days.

    Maven will make it significantly easier to understand and modify your build. If your project doesn't use Maven, I can't help you further because I'm not an Eclipse user.
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Does your project contain a pom.xml file? It's the project descriptor for a Maven build, which I'm sure Eclipse can handle these days.

    Maven will make it significantly easier to understand and modify your build. If your project doesn't use Maven, I can't help you further because I'm not an Eclipse user.


    It has a build.xml file I am not sure if that is the same but here is what was in it

     
    John McNeil
    Greenhorn
    Posts: 5
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for providing more information.  May I suggest you break down things as follows:
  • Code runs in IDE - Done
  • Make runnable JAR and run code
  • As using JDK17 I believe you will need to build a JRE to follow the article
  • Run JAR using JRE
  • Wrap JAR and JRE into an exe wrapper and run


  • Eclipse can produce a runnable JAR however, as you are using Java 17 you will have to contend with modules and importing the JFX libraries into your JAR.

    As Stephan mentioned, any file references can cause issues when moving from an IDE to a JAR.  The root of the application moves.  An easy fix for the icon image is just to comment out the use of that until you get the JAR running and then try adding it back in.  I would ask if you are using any CSS or FXML files with the JavaFX aprt of your code as these also cause the same issues.

    At the risk of self promotion, take a look at https://softwarepulse.co.uk/blog/creating-an-msi-installer-from-a-javafx-11-modular-desktop-application/ which deals with packaging up JFX modular code albeit in Java 11 which is slightly different but may help on the JAR front.

    Also there is https://softwarepulse.co.uk/blog/javafx-11-desktop-msi-application/ which is similar but avoids the modular challenges.  Again Java 11 but the JAR will probably work for you.

    Whichever route you decide to take, you need to get the JAR working first.  Let us know how you get on.
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    While I was trying to follow this tutorial to create the executable I fell upon this error while building which I do not understand


    This is my module-info file


    How do you fix them?
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The module-info.java file declares what modules your module depends on, and what packages it exports, but it doesn't actually perform any dependency management, meaning it doesn't download dependency or makes those modules available to your compiler.

    To be able to build the application using the JavaFX modules, you need to add those modules to your project's "module path". Again, since this is Eclipse without Maven, I can't help you on how to do that.

    If you ever start a new project, I really strongly implore you to use Maven to build your application instead of an Ant script.
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    They are added to my module path or am I missing something?
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It appears that way, but I'm suspicious of the JavaFX SDK entry on the class path. Can you remove it from the class path without removing it from the module path?
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:It appears that way, but I'm suspicious of the JavaFX SDK entry on the class path. Can you remove it from the class path without removing it from the module path?

    Done that and it has no effect on my project, my application works as supposed to in eclipse but once I export it into a jar it won't launch and when I tried running it using command prompt I got this instead of the error i got last time

     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Can you use an unzipper to unpack the JAR and post the contents of META-INF/MANIFEST.MF?
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ah wait sorry. I forgot that you have to run the JAR as a module. Please run the following command instead:

    You can still post the manifest though, I'm curious Eclipse puts into it.
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Can you use an unzipper to unpack the JAR and post the contents of META-INF/MANIFEST.MF?



    Yes sir here are the manifest contents


    Here is the result I got from running the command you gave me:
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Okay, so Eclipse is throwing me off, because instead of building just the JAR I'm expecting, it actually wraps your application and all its dependencies in yet another JAR. This wrapper JAR contains a custom main method that loads your application and its dependencies from the inner JARs. Presumably it does this so you can distribute your application and its dependencies as a single fat JAR, but it's kind of pointless if you're going to wrap it all up in a custom executable using launch4j.

    This means that the last commands I gave you won't work, because it messes with the class loading mechanism that Eclipse adds to the fat JAR.

    So let's go back to the command before:

    When you run this command, the custom main class that Eclipse adds to the JAR manages to load your application and the JavaFX classes inside the fat JAR, JavaFX starts up, but it crashes with the following error message: No toolkit found

    I believe this error is raised because JavaFX can't find the native libraries it needs to run on your specific operating system. These libraries aren't packaged in your fat JAR, because they are platform dependent. JavaFX looks for these libraries in the JavaFX installation folder, but you must have set up your environment variables so that this installation folder can be found.

    Did you download JavaFX explicitly, did it come with your JDK or did it come with Eclipse?
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Did you download JavaFX explicitly, did it come with your JDK or did it come with Eclipse?

    I downloaded JavaFX explicitly and then I added its Jars in a custom user library to my project. Any project I start I need to add it manually to that project or it does not work
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    That's where Maven shines. You declare the dependencies in your application, and Maven will download everything for you.

    Anyway, just downloading JavaFX wasn't enough. You need to set your environment variables to point to the directory where JavaFX is installed, so that the application can find the native libraries.

    Note that using your current approach, your customers will also have to do this.

    I'm not sure if JavaFX comes with a platform specific installer. If it does, try installing it on your system instead of just downloading the libraries.
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Due to all my fail attempts in trying to get my app to work I decided why not try out maven. So I installed intellij and followed this youtube tutorial to the letter to try and create a Hello World application export it as a jar and launch it. However, his hello world worked but not mine

    I ran in the cmd as you told me earlier and I got this


    I unpacked my jar and got the manifest contents and they are as follows:


    Youtube tutorial  followed:

     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I managed to do it somehow after following the two tutorials below, The jar is working and so is the .exe but that is only until I the MySQL database is supposed to work and the exe that does not work only the jar does. Upon user entering login details this the method that is supposed to work


    Upon successful Login I expect Entries 1,3,4,5,6 and 8 to be executed which is what gets executed when I launch from IDE or the jar, however, when I try to launch the exe Entries 1,3 and 4 gets executed and it stops. I can tell no exception has been thrown or else Entry 9 would have launched but it doesn't which means it gets stuck somehow over here

    This is how I packaged my application using jpackage


    Videos I watched, yes Mr. Stephan, I took your advice and switched my project to maven, it was a hussle but i managed and my application is probably working now

     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry, I started writing a post yesterday and only came back to it today. I just finished writing it, and it might not be relevant for you anymore, but I will post it anyway in the next post.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well, the guy starts off with a modular Maven project, and then removes module-info.java and Maven. So this tutorial gets a big FAIL sticker from me.

    Let us simply start doing everything by hand, without using your IDE (you can use your IDE to create folders and source code files and edit the files, but no compiling, running or any fancy wizards). If you know how to build and run an application using just java, javac, jar and mvn, then you can debug pretty much any problem that your IDE throws at you.

    I want you to create the following directory structure at a path that doesn't contain spaces:

    InventoryManagement/pom.xml

    InventoryManagement/src/main/java/module-info.java

    InventoryManagement/src/main/java/ibrahim/yosuf/inventory/application/InventoryManagementApplication.java

    InventoryManagement/src/main/java/ibrahim/yosuf/inventory/application/InventoryManagementFormController.java

    InventoryManagement/src/main/resources/ibrahim/yosuf/inventory/application/InventoryManagementForm.fxml

    I will elaborate on some of these files in another post, but for now I just want to see if you can get it to build and run from your command line interpreter.

    After you have everything set up, open a command line interpreter and set the working directory to InventoryManagement/ and run the following commands:

    The first command will remove all the files from a previous build, and then create and install a new build. To "install" means to put the result of the build in the local Maven repository on your system. The local Maven repository is a directory of all artifacts that you've built using Maven, and their dependencies.

    The second command will use the javafx-maven-plugin to put all the native JavaFX dependencies on the module path and run your application. I will explain more about Maven and plugins later.

    Note that for these commands to work, you have to download Maven and add its bin folder to your PATH environment variable.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    As for why your application is stuck, I couldn't really tell you. But I think in another post you mentioned that you wanted to make it easier for your customers to install a database, so couldn't you just sidestep the entire issue by using an embedded database instead of MySQL?
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:As for why your application is stuck, I couldn't really tell you. But I think in another post you mentioned that you wanted to make it easier for your customers to install a database, so couldn't you just sidestep the entire issue by using an embedded database instead of MySQL?

    I decided not to go with that solution due to future updates when I start to learn networking and have multiple devices connect to the database.

    And they are not customers :P they are family members with their own small business I am using them as lab rats for my learning journey

    Thanks btw I am going to complete the assignment you just gave me and let you know
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Yosuf Ibrahim wrote:I decided not to go with that solution due to future updates when I start to learn networking and have multiple devices connect to the database.


    Fair enough. Once you finish my tutorial, we can see if we can extend it with a MySQL database. In the mean time, tell me what MySQL version you are using and where you downloaded it from.

    And they are not customers :P they are family members with their own small business I am using them as lab rats for my learning journey


    You say that now, but if they end up using your application in their business, they will start requiring support for it and by then it's good that you have established a "customer/supplier" relationship with them.

    Thanks btw I am going to complete the assignment you just gave me and let you know


    I'm genuinely looking forward to it.
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hello, I completed the assignment and build has been successful. The app launched and worked as intded I hope, every time I pressed the button ".Hello" was rinted in the text area.

    And my other good news is I also managed to get my exe version of my app to work. Apparently the jpackaging tool is no fun when working with modules, I rewatched the videos 3 times and realized I didn't have a jmod for my the JDBC, so I tried making one for it since I couldn't find one online but that turned out a total fail after a few hours, and then I remembered that the reason I transferred my project to maven was because my jar was not working before.

    So since this time I had a working jar, I tried using Inno again, and guess what, <Drum roll> it works flawlessly and all I have to do now is try it out on other computers to see if it works just as well
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13886
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Great!

    Please show me your pom.xml, your module-info.java, and tell me what operations you perform to build and run your application.
     
    Yosuf Ibrahim
    Ranch Foreman
    Posts: 264
    6
    Eclipse IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Great!

    Please show me your pom.xml, your module-info.java, and tell me what operations you perform to build and run your application.



    pom.xml


    module-info


    Since I already had a project with the name InventoryManagement I named the this one StephanTest since it was an assignment given by you

    However, with my project mvn clean install did not work, I had to run clean first then after it was done I could run install or else it threw me an error, with yours however it worked fine
     
    when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
    Free, earth friendly heat - from the CodeRanch trailboss
    https://www.kickstarter.com/projects/paulwheaton/free-heat
    reply
      Bookmark Topic Watch Topic
    • New Topic