Error invoking method, failed to launch jvm

前端 未结 7 2176
心在旅途
心在旅途 2020-12-01 16:25

I\'m developing a desktop application using javafx v8.0.40. I have created an exe file with inno 5. When I run exe file in my computer, it is installed and run without any p

相关标签:
7条回答
  • 2020-12-01 17:02

    even though this question is a little old - today I faced the exact same problem and couldn't find any solution searching for those error messages other then here.

    The problem is pretty much identically: Built JavaFX Application (running fine on dev pc) using java 8 and packaged to native installer (exe) using Inno 5. Application ran fine on some of our machines - on others it failed with exact those to error messages:

    • "Error invoking method" and after clicking OK
    • "Failed to launch jvm".

    On application startup, the fxml loader loads the first view controller and calls its "initialize" method. If - within initialize - an unhandeled exception is being thrown, the application crashes and those two windows error messages are shown.

    Hope that this will help some one who like me is struggling with that, too.

    0 讨论(0)
  • 2020-12-01 17:04

    I ran into the same problem; the following worked for me and helped me make sense of those blasted "Error invoking method." and "Failed to launch JVM" dialogs:

    1. Find your .jar file
      • It has the same name as your Project and it's in your application's installation directory under AppData\Local\{ApplicationTitle}\app (shortcut: type %appdata% into explorer); if your project was named HelloWorld, there you will find HelloWorld.jar
    2. Navigate to it's directory in command prompt
      • shift+Right Click any blank spot in the Explorer window and choose "Open command window here" (that's a fancy trick I recently learned; alternatively you would cd to the same directory using the command prompt)
    3. Run your .jar via the command line
      • type java -jar "HelloWorld.jar" and hit Enter

    Tadah! Behold your hidden exceptions (the existence of which "Error invoking method." so vaguely tries to communicate to you). *

    If your problem is similar to mine it stems from a file structure difference between the project out folder and the installation directory, and that's why the program compiles just fine in the editor and builds just fine—there isn't a problem until it's built out, and the file structure is a little different.

    *If you didn't get anything when you ran it via the command line, look for any errors that could be happening during that initialize() method; that's where your problem likely is. You can expose any exceptions during runtime by using a Popup Exception Dialog like shown in a similar problem, here.

    0 讨论(0)
  • 2020-12-01 17:04

    You could experience this error if you didn't include the third-party libraries to the build.

    The following can be placed in the build.xml just before the end tag of the project.

    <target name="-post-jfx-deploy">
        <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" nativeBundles="all"
                   outdir="${basedir}/${dist.dir}" outfile="${application.title}">
            <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
            <fx:resources>
                <fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/>       
                <fx:fileset dir="${basedir}/${dist.dir}" includes="lib/*.jar"/>
            </fx:resources>
            <fx:info title="${application.title}" vendor="${application.vendor}"/>
        </fx:deploy>           
    

    0 讨论(0)
  • 2020-12-01 17:05

    This is probably because it lacks the dependencies in the output jar. So you need to add the libraries in the artifact and then .exe generation should be ok.

    Here is an example with Intellij, where the libraries have be manually moved from "Available Elements" to the artifact

    Intellij example

    0 讨论(0)
  • 2020-12-01 17:11

    I could not fix the problem, but I found a way around it. I used notepad to create a batch file to launch the app. First I used cd to get to the directory of the .jar file and then used java -jar to launch the app. It should look something like this:

    cd C:\[wherever your project folder is located]\[name of project]\dist
    java -jar [name of project].jar
    

    Save it as a .bat file on the desktop, launch the batch file and your program will boot!

    0 讨论(0)
  • 2020-12-01 17:11

    I just had this issue and @Brad Turek's answer pointed me at the right direction. Except it wasn't my code that throw the exception.

    The .cfg file (at /<app_name>/app/<app_name>.cfg) that the .exe wrapper used to start my application had incorrectly pointed to libs (jar files) that didn't exist at the /lib directory. Which (I concluded) caused the classloader to throw and terminate the startup.

    After correcting the .cfg file everything worked fine.

    0 讨论(0)
提交回复
热议问题