错误调用方法.并且未能启动JVM-本机软件包将构建但不会启动



任何人都可以更具体地对我的问题所居住的地方和如何修复?

我正在运行:

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

我已经仔细遵循了Marco上的指示。Marco在Code.makery.ch(code.makery.ch/library/javafx-8-tutorial/part7/part7/)

之前,我已经部署了此程序的较早本机软件包,但有些麻烦,但最终在添加

之后成功地成功了
-vm
C:Program FilesJavajdk1.8.0_91binjavaw.exe

to eclipse.ini

最终成功运行蚂蚁之后,

do-deploy:
        [copy] Copying 2 files to C:Usersadministrator.SUNDANCEIdeaProjectsPOA 1.1 Build MasterPOA 1.1 - Try 1builddistlibs
       [mkdir] Created dir: C:Usersadministrator.SUNDANCEIdeaProjectsPOA 1.1 Build MasterPOA 1.1 - Try 1buildbuildclassesMETA-INF
Using base JDK at: C:Program FilesJavajdk1.8.0_91jre
Using base JDK at: C:Program FilesJavajdk1.8.0_91jre
Installer (.exe) saved to: C:Usersadministrator.SUNDANCEIdeaProjectsPOA 1.1 Build MasterPOA 1.1 - Try 1builddeploybundles
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);
    }
}

我的包装探险家看起来像这样,如果有帮助我的道路:C:ProgramDataOracleJavajavapath;%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;%SYSTEMROOT%System32WindowsPowerShellv1.0;C:Program Files (x86)IBMClient AccessEmulator;C:Program Files (x86)IBMClient AccessShared;C:Program Files (x86)IBMClient Access;C:Program FilesMicrosoft SQL Server110DTSBinn;C:Program Files (x86)Microsoft SQL Server110ToolsBinnManagementStudio;C:Program Files (x86)Microsoft SQL Server110ToolsBinn;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEPrivateAssemblies;C:Program Files (x86)Microsoft SQL Server110DTSBinn;C:Program FilesTortoiseHg;C:Program Files (x86)Inno Setup 5

build.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}..libant-javafx.jar"/>
                <file name="${java.home}libjfxrt.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 FilesJavasqljdbc_4.2enu">
                <filename name="sqljdbc42.jar"/>
            </fileset>
        </copy>
        <copy todir="externalLibs">
            <fileset dir="C:Usersadministrator.SUNDANCEIdeaProjectsPOA 1.1 Build MasterPOA 1.1 - Try 1builddist">
                <filename name="POA 1.1 - Try 1.jar"/>
            </fileset>
        </copy>
        <mkdir dir="project" />
        <copy todir="project">
            <fileset dir="C:Usersadministrator.SUNDANCEIdeaProjectsPOA 1.1 Build MasterPOA 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中编译并运行良好,但是当我运行安装版本时,我会得到:

错误调用方法。

首先,然后单击OK

无法启动JVM

我似乎尝试了一切:

我已经阅读了多个类似的问题,并且已经搜寻了互联网,但是尚未衡量这个问题。我读过的许多人都有含糊或没有答案的示例:

  • 错误调用方法,无法启动JVM

  • javafx本机pakage错误调用方法

因为他在部署方面不太熟练,所以马可本人说来询问堆栈交流的强大世界:http://code.makery.ch/library/javafx-8-tutorial/part7/#comment-2233862311

再次,关于我的问题所在的位置以及如何修复它的任何特定启示?

我发现了它!

我发现问题的方式:

double之后,三重检查依赖项并看到它既编译然后构建正常,又怀疑位于 build/deploy/{yourProjectName}.jar

的jar文件

编辑:如果您仅在安装错误后得到错误,则在安装目录中运行JAR是有意义的。(AppData/Local/{ApplicationTitle}/app/{yourProjectName}.jar

我在命令行上运行它,以查看它是否正在抛出例外:

要轻松导航到目录,我指出了我将项目保存在Explorer中的位置,然后将其复制到命令行。

  1. 打开命令提示

    win r

    cmd enter

  2. 导航到目录

    cd {ProjectPath}builddeploy

  3. 运行jar文件

    java -jar "{YourJar}.jar"

因为我是通过命令提示执行罐子的,所以爪哇可以向我展示例外!

C:Usersadministrator.SUNDANCEIdeaProjectsPODTester_Layout8builddeploy>java
 -jar "PODTester_Layout8.jar"
java.io.FileNotFoundException: srcresourcesCarrier 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的明确引用,它没有找到该文件。我修复了,然后看!重建后,已安装的应用程序工作!


因此,总结:

如果您的本机软件包会抛出

错误调用方法。

无法启动JVM

通过命令提示运行JAR文件,查看是否引发异常。


现在,如果您想要有关我的特定问题的详细信息以及我要修复的过程,那么您就可以了:

问题:

我认为这可能与依赖关系有关(尤其是与我在内的SQLJDBC驱动程序)有关,但事实证明,这不是一个依赖问题。问题是 .jar曾经安装了一个例外一旦安装使错误如此难以理解的是OH-So-So-seneric"无法调用方法"。"这给了我很少的新信息。

为了减轻未来的类似问题,我添加了showExceptionDialog()方法(受Marco Jacob的工作启发):

/**
 * 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() + "nn";
    }
    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文件夹中。

在Intellij和Eclipse中,它可以很好地编译,因为它可以找到src/resources/Carrier List.txt。当我根据Marco Jacob的部署教程手动复制资源文件夹时,情况就很好了,但是我明确引用了

src /resources/carrier list.txt

在我的代码中而不是

资源/运营商列表