调用错误方法。并且无法启动JVM - 本地软件包将构建但不启动 [英] Error invoking method. and Failed to launch JVM - Native Package will build but not launch
问题描述
任何人都可以更明确地说明我的问题所在的地方,以及如何解决?
我正在运行: / p>
- 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]将2个文件复制到C:\Users\administrator.SUNDANCE \IdeaProjects\POA 1.1构建Master\POA 1.1 - 尝试1\build\dist\libs
[mkdir]创建dir:C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - 尝试1\build\build\classes\META-INF
在以下位置使用基本JDK:C:\Program Files\Java\jdk1.8.0_91\jre
使用基本JDK:C:\Program Files\Java\jdk1.8.0 _91\jre
安装程序(.exe)保存到:C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1构建Master\POA 1.1 - 尝试1\build\deploy\捆绑
BUILD SUCCESSFUL
总时间:56秒
我的主文件看起来像这个:
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;
/ **
*由Brad于5/20/2016创建。
*仅用于加载FXML并设置图标。一切都在Controller.java中完成
* /
public class Main extends Application {
public static FXMLLoader loader;
// https://icons8.com上的图标
@Override
public void start(Stage primaryStage)throws Exception {
loader = new FXMLLoader();
loader.setLocation(Main.class.getResource(view / Arrivals_Layout1.fxml));
父根= 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(采购订单到达);
primaryStage.setScene(new Scene(root));
primaryStage.setMinWidth(820);
primaryStage.setMinHeight(375);
primaryStage.show();
}
public static void main(String [] args){
launch(args);
}
}
我的Package Explorer看起来像这个,如果它有助于
我的PATH: 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文件(x86)\Microsoft SQL Server\110\Tools\\ \\ Binn\ManagementStudio\; C:\程序文件(x86)\Microsoft SQL Server\110\Tools\Binn\; C:\Program Files\Microsoft SQL Server\110\ Tools\Binn\; C:\Program文件(x86)\Micro软件Visual Studio 10.0\Common7\IDE\PrivateAssemblies\; C:\程序文件(x86)\Microsoft SQL Server\110\DTS\Binn\; C:\Program Files\ TortoiseHg\; C:\程序文件(x86)\Inno安装程序5
build.xml:
<?xml version =1.0encoding =UTF-8?>
< project name =POA 1.1 - 尝试1default =do-deploybasedir =。的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 - 尝试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 - 尝试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/>
<! - 复制project-libs引用 - >
< copy todir =build / libs>
< fileset dir =externalLibs>
< include name =sqljdbc42.jar/>
< include name =POA 1.1 - 尝试1.jar/>
< / fileset>
< / copy>
<! - 复制项目引用 - >
<! - 复制项目源本身 - >
< copy todir =build / src>
< fileset dir =project / src>
< include name =** / */>
< / fileset>
< / copy>
< javac includeantruntime =falsesource =1.8target =1.8srcdir =build / srcdestdir =build / classesencoding =Cp1252>
< classpath>
< fileset dir =build / libs>
< include name =*/>
< / fileset>
< / classpath>
< / javac>
<! - 复制无Java文件 - >
< copy todir =build / classes>
< fileset dir =project / src>
< exclude name =** / *。java/>
< / fileset>
< / copy>
< / target>
< target name =do-deploydepends =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 =distincludes =POA 1.1 - 尝试1.jar/>
< fx:fileset dir =distincludes =libs / */>
< fx:fileset dir =distincludes =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 - 尝试1.jar>
< fx:application refid =fxApplication/>
< fileset dir =build / classes>
< / fileset>
< fx:resources refid =appRes/>
< manifest>
< attribute name =Implementation-Vendorvalue =Ugma Development/>
< attribute name =Implementation-Titlevalue =Purchase Order Arrivals/>
< attribute name =Implementation-Versionvalue =1.1/>
< attribute name =JavaFX-Feature-Proxyvalue =None/>
< / manifest>
< / fx:jar>
< mkdir dir =部署/>
<! - 需要使用$ {basedir},因为不知何故蚂蚁任务正在不同地计算目录 - >
< fx:deploy
embedJNLP =false
extension =false
includeDT =false
offlineAllowed =true
outdir =$ {basedir} / deploy
outfile =POA 1.1 - 尝试1nativeBundles =exe
updatemode =background>
< fx:platform basedir =$ {java.home}/>
< fx:info title =POA 1.1 - Try 1vendor =Ugma Development/>
< fx:application refId =fxApplication/>
< fx:resources refid =appRes/>
< / fx:deploy>
< / target>
< / project>
生成.exe并将程序安装在/ AppData中。
程序将在Eclipse中编译并运行正常,但是当我运行安装的版本时,我得到:
错误调用方法。
然后单击确定
无法启动JVM
我已经尝试了一切:
我已经阅读过多个类似的问题,并已经浏览了互联网,但还没有提交这个问题。我读过的很多模糊或没有答案的例子:
由于他在部署方面不太熟练,Marco自己说来问问Stack Exchange的强大世界:
http://code.makery.ch/library/javafx-8-tutorial/part7/# comment-2233862311
同样,我的问题所在的任何特定的光线,以及如何解决?
我想出来了!
我发现问题:
之后仔细检查依赖关系,并看到它们都被编译然后构建正确,我怀疑位于 build / deploy / {yourProjectName} .jar
编辑:如果您仅在安装完成错误后才能在安装目录中运行该jar。 ( AppData / Local / {ApplicationTitle} / app / {yourProjectName} .jar
)
命令行查看是否抛出异常:
为了方便浏览到目录,我注意到我在Explorer中保存了我的项目,然后将其复制到命令行
-
打开命令提示符
kbd> + r
cmd
+ 输入 / p> -
导航到目录
cd {ProjectPath} \build\\ \\ deploy
-
运行jar文件
java -jar{YourJar} .jar
因为我执行jar通过命令提示符,java有一个地方告诉我异常!
C:\Users\administrator.SUNDANCE\\ \\IdeaProjects\PODTester_Layout8\build\deploy> java
-jarPODTester_Layout8.jar
java.io.FileNo tFoundException:src\resources\Carrier List.txt(系统不能
找到指定的路径)
在java.io.FileInputStream.open0(本机方法)
在java.io. FileInputStream.open(未知源)
在java.io.FileInputStream。< init>(未知源)
在java.io.FileInputStream。< init>(未知来源)
at java.io.FileReader。< init>(未知来源)
在查看我的代码后,因为没有找到该文件,因为显式地引用了 src
。我固定了,而且看着!重建后,已安装的应用程序正常工作!
总结如下:
如果您的本机包为您提供
错误调用方法。
和
无法启动JVM
通过命令提示符运行您的jar文件,看看它是否引发异常。
现在,如果您想了解有关我的具体问题的详细信息以及我经历的过程来解决问题,请点击:
问题:
我以为这可能与依赖关系有关(特别是与我一起,包括sqljdbc驱动程序)但事实证明这不是一个依赖问题。问题是,安装之后,只有.jar才会抛出异常。。这个错误非常难以理解的是无法调用的方法。 这给了我一些新的信息。
为了减轻未来的类似问题,我添加了一个 showExceptionDialog()
方法(灵感来自 Marco Jacob的作品):
/ **
*当出现异常时显示对话框,而不是什么也不做。
*
*一旦安装,这将有助于诊断问题,而不是让
*他们不被注意。
*
* @param e打印例外它的堆栈跟踪将被显示为
* /
public static void showExceptionDialog(Exception e){
警报警报=新警报(Alert.AlertType.ERROR);
alert.setTitle(异常对话框);
alert.setHeaderText(发生错误);
String content =Error:;
if(null!= e){
content + = e.toString()+\\\
\\\
;
}
alert.setContentText(content);
异常ex = new异常(e);
//创建可扩展异常。
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String exceptionText = sw.toString();
//设置TextArea
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setPrefHeight(600);
textArea.setPrefWidth(800);
//将展开式异常设置到对话窗格中。
alert.getDialogPane()。setExpandableContent(textArea);
alert.showAndWait();
}
有关我的问题的具体细节:
在我的程序中,我有一个名为 Carrier List.txt
的文件被读取和写入,存储在资源
文件夹中。
在IntelliJ和Eclipse中,它编译得很好,因为它可以找到 src / resources / Carrier List.txt
刚好当我按照 Marco Jacob的手动复制资源文件夹时,事情会很好部署教程,但是我明确地引用了
src / resources / Carrier List.txt < p $ $ $ $ $ $ $ $ $ $ $ $
$ p $ / Carrier List.txt
Can anyone shed any light more specifically on where my problem resides, and how to fix it?
I'm running:
- Windows 7
- Eclipse Mars.2 Release (4.5.2)
I've followed the instructions closely and repeatedly for Marco's Tutorial on code.makery.ch (code.makery.ch/library/javafx-8-tutorial/part7/)
I've deployed an earlier native package of this program before, with some trouble, but eventually successfully after adding
-vm
C:\Program Files\Java\jdk1.8.0_91\bin\javaw.exe
to eclipse.ini
After finally getting the ant build to run successfully,
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
My main file looks like this:
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);
}
}
My Package Explorer looks something like this, if it helps
My PATH: 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
The 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}\..\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>
The .exe is generated and installs the program in /AppData.
The program will compile and run fine in Eclipse, but when I run the installed version, I get:
Error invoking method.
first and then after clicking OK
Failed to launch JVM
I've tried seemingly everything:
I've read multiple similar questions, and have scoured the internet, but have yet to vault this problem. Examples of the many I've read with vague or no answers:
Because he is less masterful in deployment, Marco himself said to come ask the mighty world of Stack Exchange: http://code.makery.ch/library/javafx-8-tutorial/part7/#comment-2233862311
Again, any specific light on where my problem resides, and how to fix it?
I figured it out!
The way I found the problem:
After double, triple checking the dependencies and seeing that it both compiled and then built fine, I suspected the jar file which is located at build/deploy/{yourProjectName}.jar
EDIT: If you're getting the errors only once it is installed, it makes sense to run the jar in the installation directory. ( AppData/Local/{ApplicationTitle}/app/{yourProjectName}.jar
)
I ran it on the command line to see if it was throwing an exception:
To easily navigate to the directory I noted where I had saved my project in Explorer and then copied that to the command line.
Open command prompt
Win + r
cmd
+ EnterNavigate to the directory
cd {ProjectPath}\build\deploy
Run the jar file
java -jar "{YourJar}.jar"
Because I executed the jar via the command prompt, java had somewhere to show me the exception!
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)
Upon reviewing my code, I figured that it wasn't finding the file because of the explicit reference to src
. I fixed that and lo and behold! Upon rebuilding, the installed application worked!
So in summary:
If your native package throws you a
Error invoking method.
and a
Failed to launch JVM
run your jar file via the command prompt to see if it throws exceptions.
Now if you want details about my specific problem and the process I went through to fix it, here you go:
The Problem:
I thought it might've been something to do with dependencies (especially with me including the sqljdbc driver), but it turns out it wasn't a dependency issue. The problem was that the .jar was throwing an exception only once installed. What made the error so hard to understand was the oh-so-generic "Could not invoke method." which gave me little new information.
To mitigate future similar problems I added a showExceptionDialog()
method (inspired by Marco Jacob's work) :
/**
* 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();
}
Specific details about my problem:
In my program I had a file called Carrier List.txt
being read and written to, and it was stored in the resources
folder.
In IntelliJ and Eclipse it compiled just fine because it could find src/resources/Carrier List.txt
just fine. Things would have been just fine when I manually copied the resources folder as per Marco Jacob's Deployment Tutorial, but I explicitly referenced
src/resources/Carrier List.txt
in my code instead of just
resources/Carrier List.txt
这篇关于调用错误方法。并且无法启动JVM - 本地软件包将构建但不启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!