调用方法时出错。无法启动 JVM - 本机包将构建但无法启动

2023-12-05

谁能更具体地说明我的问题所在以及如何解决它?

我在跑:

  • Windows 7的
  • Eclipse Mars.2 版本 (4.5.2)

我已经反复严格按照 Marco 的 code.makery.ch 教程 (code.makery.ch/library/javafx-8-tutorial/part7/) 上的说明进行操作

我之前部署过该程序的早期本机包,遇到了一些麻烦,但在添加后最终成功

-vm
C:\Program Files\Java\jdk1.8.0_91\bin\javaw.exe

到 eclipse.ini

最终让ant构建成功运行后,

do-deploy:
        [copy] Copying 2 files to C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1\build\dist\libs
       [mkdir] Created dir: C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1\build\build\classes\META-INF
Using base JDK at: C:\Program Files\Java\jdk1.8.0_91\jre
Using base JDK at: C:\Program Files\Java\jdk1.8.0_91\jre
Installer (.exe) saved to: C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1\build\deploy\bundles
BUILD SUCCESSFUL
Total time: 56 seconds

我的主文件如下所示:

 import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

/**
 * Created by Brad on 5/20/2016.
 * Solely used to load the FXML and set the icons. Everything else is done in Controller.java
 */
public class Main extends Application {
    public static FXMLLoader loader;

    //Icon from https://icons8.com

    @Override
    public void start(Stage primaryStage) throws Exception{
        loader = new FXMLLoader();
        loader.setLocation(Main.class.getResource("view/Arrivals_Layout1.fxml"));
        Parent root = loader.load();
        primaryStage.getIcons().add(new Image(ClassLoader.getSystemResourceAsStream("resources/images/Pallet-96.png")));
        primaryStage.getIcons().add(new Image(ClassLoader.getSystemResourceAsStream("resources/images/pallet_96_allsizes.ico")));



        primaryStage.setTitle("Purchase Order Arrivals");
        primaryStage.setScene(new Scene(root));
        primaryStage.setMinWidth(820);
        primaryStage.setMinHeight(375);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

我的包资源管理器看起来像this,如果有帮助的话 我自己的路:C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\IBM\Client Access\Emulator;C:\Program Files (x86)\IBM\Client Access\Shared;C:\Program Files (x86)\IBM\Client Access\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\Inno Setup 5

构建.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <project name="POA 1.1 - Try 1" default="do-deploy" basedir="."  xmlns:fx="javafx:com.sun.javafx.tools.ant">
    <target name="init-fx-tasks">
        <path id="fxant">
            <filelist>
                <file name="${java.home}\..\lib\ant-javafx.jar"/>
                <file name="${java.home}\lib\jfxrt.jar"/>
                <file name="${basedir}"/>
            </filelist>
        </path>

        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
            uri="javafx:com.sun.javafx.tools.ant"
            classpathref="fxant"/>
    </target>
    <target name="setup-staging-area">
        <delete dir="externalLibs" />
        <delete dir="project" />
        <delete dir="projectRefs" />

        <mkdir dir="externalLibs" />

        <copy todir="externalLibs">
            <fileset dir="C:\Program Files\Java\sqljdbc_4.2\enu">
                <filename name="sqljdbc42.jar"/>
            </fileset>
        </copy>
        <copy todir="externalLibs">
            <fileset dir="C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1\build\dist">
                <filename name="POA 1.1 - Try 1.jar"/>
            </fileset>
        </copy>

        <mkdir dir="project" />
        <copy todir="project">
            <fileset dir="C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1">
                <include name="src/**" />
            </fileset>
        </copy>

        <mkdir dir="projectRefs" />
    </target>
    <target name='do-compile'>
        <delete dir="build" />
        <mkdir dir="build/src" />
        <mkdir dir="build/libs" />
        <mkdir dir="build/classes" />

        <!-- Copy project-libs references -->
        <copy todir="build/libs">
            <fileset dir="externalLibs">
                <include name="sqljdbc42.jar"/>
                <include name="POA 1.1 - Try 1.jar"/>
            </fileset>
        </copy>

        <!-- Copy project references -->

        <!-- Copy project sources itself -->
        <copy todir="build/src">
            <fileset dir="project/src">
                <include name="**/*"/>
            </fileset>
        </copy>

        <javac includeantruntime="false" source="1.8" target="1.8" srcdir="build/src" destdir="build/classes" encoding="Cp1252">
            <classpath>
                <fileset dir="build/libs">
                    <include name="*"/>
                </fileset>
            </classpath>
        </javac>

        <!-- Copy over none Java-Files -->
        <copy todir="build/classes">
        <fileset dir="project/src">
            <exclude name="**/*.java"/>
        </fileset>
        </copy>


    </target>
    <target name="do-deploy" depends="setup-staging-area, do-compile, init-fx-tasks">
        <delete file="dist"/>
        <delete file="deploy" />

        <mkdir dir="dist" />
        <mkdir dir="dist/libs" />

        <copy todir="dist/libs">
            <fileset dir="externalLibs">
                <include name="*" />
            </fileset>
        </copy>


        <fx:resources id="appRes">
            <fx:fileset dir="dist" includes="POA 1.1 - Try 1.jar"/>
            <fx:fileset dir="dist" includes="libs/*"/>
            <fx:fileset dir="dist" includes="resources/**"/>
        </fx:resources>

        <fx:application id="fxApplication"
            name="Purchase Order Arrivals"
            mainClass="Main"
            version="1.1"
        />

        <mkdir dir="build/classes/META-INF" />



        <fx:jar destfile="dist/POA 1.1 - Try 1.jar">
            <fx:application refid="fxApplication"/>
            <fileset dir="build/classes">
            </fileset>
            <fx:resources refid="appRes"/>

            <manifest>
                <attribute name="Implementation-Vendor" value="Ugma Development"/>
                <attribute name="Implementation-Title" value="Purchase Order Arrivals"/>
                <attribute name="Implementation-Version" value="1.1"/>
                <attribute name="JavaFX-Feature-Proxy" value="None"/>
            </manifest>
        </fx:jar>


        <mkdir dir="deploy" />
        <!-- Need to use ${basedir} because somehow the ant task is calculating the directory differently -->
        <fx:deploy
            embedJNLP="false"
            extension="false"
            includeDT="false"
            offlineAllowed="true"
            outdir="${basedir}/deploy"
            outfile="POA 1.1 - Try 1" nativeBundles="exe"
            updatemode="background" >

            <fx:platform basedir="${java.home}"/>
            <fx:info title="POA 1.1 - Try 1" vendor="Ugma Development"/>

            <fx:application refId="fxApplication"/>
            <fx:resources refid="appRes"/>
        </fx:deploy>


    </target>
</project>

生成 .exe 并将程序安装在 /AppData 中。

该程序将在 Eclipse 中编译并正常运行,但是当我运行已安装的版本时,我得到:

调用方法时出错。

首先,然后单击“确定”后

无法启动 JVM

我似乎已经尝试了一切:

我读过多个类似的问题,并搜索过互联网,但尚未解决这个问题。我读过的许多答案含糊或没有答案的例子:

  • 调用方法出错,启动jvm失败

  • javafx本机包调用方法出错

由于自己不太擅长部署,Marco 自己说要来问问 Stack Exchange 的强大世界:http://code.makery.ch/library/javafx-8-tutorial/part7/#comment-2233862311

再说一遍,有没有具体说明我的问题出在哪里以及如何解决?


我想到了!

我发现问题的方式:

经过双重、三次检查依赖关系并看到它都编译并构建良好后,我怀疑 jar 文件位于build/deploy/{yourProjectName}.jar

EDIT:如果仅在安装后才出现错误,则在安装目录中运行 jar 是有意义的。 (AppData/Local/{ApplicationTitle}/app/{yourProjectName}.jar )

我在命令行上运行它以查看它是否抛出异常:

为了轻松导航到我在资源管理器中保存项目的目录,然后将其复制到命令行。

  1. 打开命令提示符

    Win + r

    cmd + Enter

  2. 导航至目录

    cd {ProjectPath}\build\deploy

  3. 运行jar文件

    java -jar "{YourJar}.jar"

因为我通过命令提示符执行了 jar,所以 java 有地方向我显示异常!

C:\Users\administrator.SUNDANCE\IdeaProjects\PODTester_Layout8\build\deploy>java
 -jar "PODTester_Layout8.jar"
java.io.FileNotFoundException: src\resources\Carrier List.txt (The system cannot
 find the path specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileReader.<init>(Unknown Source)

在检查我的代码后,我发现它没有找到该文件,因为明确引用了src。我解决了这个问题,你瞧!重建后,安装的应用程序就可以工作了!


总结来说:

如果您的本机软件包给您带来了

调用方法时出错。

and a

无法启动 JVM

通过命令提示符运行 jar 文件以查看它是否引发异常。


现在,如果您想了解我的具体问题以及我解决该问题的过程的详细信息,请访问:

问题:

我认为这可能与依赖关系有关(特别是对我而言,包括 sqljdbc 驱动程序),但事实证明这不是依赖关系问题。问题是.jar 仅抛出异常一旦安装.导致错误如此难以理解的是“无法调用方法”。这给了我很少的新信息。

为了缓解未来类似的问题,我添加了一个showExceptionDialog()方法(灵感来自马可·雅各布的作品) :

/**
 * Shows a dialog box when an exception occurs instead of just doing nothing.
 *
 * Once installed this will help to diagnose problems instead of letting
 * them go unnoticed.
 *
 * @param e the exception to print; it's stacktrace will be shown as well
 */
public static void showExceptionDialog(Exception e) {
    Alert alert = new Alert(Alert.AlertType.ERROR);

    alert.setTitle("Exception Dialog");
    alert.setHeaderText("An error occurred:");

    String content = "Error: ";
    if (null != e) {
        content += e.toString() + "\n\n";
    }

    alert.setContentText(content);

    Exception ex = new Exception(e);

    //Create expandable Exception.
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ex.printStackTrace(pw);

    String exceptionText = sw.toString();

    //Set up TextArea
    TextArea textArea = new TextArea(exceptionText);
    textArea.setEditable(false);
    textArea.setWrapText(true);


    textArea.setPrefHeight(600);
    textArea.setPrefWidth(800);


    //Set expandable Exception into the dialog pane.
    alert.getDialogPane().setExpandableContent(textArea);


    alert.showAndWait();
}

关于我的问题的具体细节:

在我的程序中,我有一个名为Carrier List.txt被读取和写入,并且它被存储在resources folder.

在 IntelliJ 和 Eclipse 中它编译得很好,因为它可以找到src/resources/Carrier List.txt正好。当我按照以下方式手动复制资源文件夹时,一切都会好起来的Marco Jacob 的部署教程,但我明确引用了

src/resources/运营商列表.txt

在我的代码中而不是仅仅

资源/运营商列表.txt

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

调用方法时出错。无法启动 JVM - 本机包将构建但无法启动 的相关文章

  • cordova 添加平台 - 执行命令“ant”时出错

    在一开始的时候 我知道这个问题已经被问了太多次了 我检查了所有的答案 尝试了我发现的每一种组合和每一种解决方案 但到目前为止没有任何效果对我有用 问题 我已经成功安装了cordova 从官方网站下载了它 并且我一直在遵循指南 我已经添加wp
  • Docker:如何创建堆栈、多个映像或一个基础映像?

    I am new using Docker and I got the doubt of using one image base for my stack or I have to define each image depending
  • 从 Java 内部限制 CPU

    我在这个 和其他 论坛中看到了许多具有相同标题的问题 但似乎没有一个问题能完全解决我的问题 就是这个 我有一个 JVM 它占用了托管它的机器上的所有 CPU 我想限制它 但是我不能依赖任何限制工具 技术external到 Java 因为我无
  • 使用translateX()和translateY()时,窗格布局内的JavaFX文本与其他元素重叠

    下图是对正在发生的情况的描述 我有一个Pane其中包含一个Text我正在使用下面的代码来制作marquee like effect of the Text 所以当Pane没有足够的空间来显示文本 动画正在开始 文本必须来回移动 以便用户可以
  • Linux 软件包存储库中的 *​​-dev 软件包实际上包含什么?

    我的问题非常基本 我现在的知识也是如此 我是 Linux 的长期用户 但直到最近才对编程产生了浓厚的兴趣 我看到 Ubuntu 存储库中的许多流行应用程序都有 dev 软件包 例如洋泾浜开发者此外pidgin 我的问题是这样的 这些包裹里有
  • 如何平滑拖动JavaFX多边形?

    我有一个多边形 三角形 我想让它可以用鼠标拖动 下面是我尝试过的代码 但是使用此代码我无法顺利拖动它 请让我知道如何才能使其顺利拖动 public void start Stage primaryStage throws Exception
  • 排除jar中的文件进入apk

    我最近添加了一些新的罐子到我的android项目 一些 jar 包含 version properties 其中之一甚至包含 README TXT 我如何告诉 eclipse adt ant 排除文件进入 apk 显然我可以解压 apk 删
  • SSIS - 在整个项目中更改对变量/参数的引用

    我创建了一个 SSIS 项目 认为它将以项目部署模式进行部署 我的很多包都有 2 个参数 称为P OdsTbl and P SrcEtl 每当我使用执行包任务时 我都会将子参数绑定到父参数 我发现该项目将以包部署模式部署 这意味着我需要将参
  • 如何在 JavaFX 中设置滚动窗格的单位增量?

    The 滚动条 http docs oracle com javafx 2 api javafx scene control ScrollBar htmlJavaFX 中的类包含一个用于设置单位增量的属性 这就是我所追求的 但是我找不到如何
  • Tomcat 热部署到托管多个应用程序的实例

    我的问题是关于部署到托管多个应用程序并托管 Struts Spring 和 Hibernate 的应用程序上下文的 Tomcat 服务器实例 我想在不重新启动 Tomcat 服务器的情况下将更改部署到一个应用程序 举个例子 在我们公司很多时
  • 哪个更快:instanceof 或 isInstance?

    抛开设计问题不谈 什么在现代 JVM 上执行得更快 foo instanceof Bar or Bar class isInstance foo Why Class isInstance是 JVM 固有的 它被编译为与instanceof完
  • 将TableView数据显示到另一个窗口中包含JavaFx中的TextField

    我制作了两个 Fxml 文件 一个包含 TextField 另一个包含 TableView 它有它的 Controller 类 我想在执行鼠标单击操作事件时显示从 TableView 到 TextField 的数据 但我们没有得到结果 它显
  • JavaFX 拖放无法正常工作

    我在网格窗格中使用两个 Imageview 进行拖放测试 我的问题是 当我完成拖放并将目标图像视图移动到源图像视图并释放鼠标时 我错误地最终显示了 img2 中的图片 而不是 img1 中的图片 当我注释掉 setOnDragExited
  • 我在使用 JavaFX 绘制十字时遇到问题

    我正在尝试编写代码 在网格上对角绘制 3 个形状 前两个形状是正方形和圆形 我能做到 然而 第三种形状让我有些悲伤 我应该画一个十字 T 版本 而不是 X 每次我写出代码时 它看起来就像一个侧面 我知道我只是错过了一些简单的东西 但我真的很
  • 如何在JavaFX中有效地滚动和缩放大图像?

    作为图像处理应用程序的一部分 我需要创建具有缩放 滚动和矢量叠加功能的简单查看器模块 图像相当大 40000x20000 这使得 ImageView 上的操作变慢 缓冲等 在 JavaFX 中处理巨大图像时 改善用户体验的最佳选项是什么 我
  • Angular2通用部署到apache远程服务器

    我在将 Web 应用程序部署到 Apache 远程服务器时遇到问题 我已经通过以下步骤部署了一个使用 RESTful API 服务 用 PHP 编写 托管在 public html api 的标准 Angular2 Web 应用程序 在项目
  • Mac OS X 下的 JavaFX:系统菜单和模态窗口

    我目前面临 Mac OS X 下的 JavaFX 菜单和模式对话框的问题 我正在使用该方法 MenuBar setUseSystemMenuBar true 为了将系统菜单栏用于我的应用程序菜单 这工作正常 但如果模式对话框打开 菜单不会被
  • 在 Sublime Text 3 中安装多个包

    在 Sublime Text 3 中安装软件包时 我是否可以从列表中勾选所有我想要的软件包 然后一次性安装它们 或者对于我想要安装的每个软件包 我是否必须单击 首选项 gt 软件包控制 gt 安装软件包 例如 Notepad 有一个很好的带
  • 绘制圆和连接这些圆的曲线

    我需要绘制一些圆圈和连接这些圆圈的曲线 圆圈必须以行和列的方式绘制 所以我想使用 GridPane 将是一个不错的选择 但是 绘制完所有圆圈后 如何添加曲线来连接属于此 GridPane 上不同列的圆圈 我无法将 GridPane add
  • Rails Capistrano 3 - 如何将 production.log 文件共享到 Capistrano 的共享文件夹中?

    我正在使用 Capistrano 3 与我的 Rails 应用程序一起部署 问题是 每次我将应用程序部署到服务器时 log development log 文件都会重置 我听说可以将 production log 文件放入共享文件夹中并在每

随机推荐