简体   繁体   English

我是否跳过了 JRE 和 Launch4j 的必要步骤导致我的 exe 文件失败?

[英]Did I skip necessary steps for my JRE and in Launch4j to cause my exe file to fail?

There were some initial issues with my javac.exe not working with the rest of the software to be able to compile and run the code, yet I was able to get a .class and .java for the program, so I thought I could use Launch4j to still create the application to execute normally by itself.我的 javac.exe 存在一些初始问题,无法与软件的其余部分一起使用,无法编译和运行代码,但我能够为程序获取 .class 和 .java,所以我想我可以使用Launch4j 仍然创建应用程序以自行正常执行。 However, I don't know why the .exe produced does not provide the output I expect.但是,我不知道为什么生成的 .exe 没有提供我期望的输出。

I used a guide that you are probably aware of to learn to test a "HelloWorld" program since I am new to java and turning actual code into applications.我使用了一个您可能知道的指南来学习测试“HelloWorld”程序,因为我是 Java 新手并将实际代码转换为应用程序。 Following the procedures, I was able to get up to testing the javac.exe file, to which I found out my JDK version somehow does not properly install one.按照这些程序,我能够开始测试 javac.exe 文件,我发现我的 JDK 版本以某种方式没有正确安装一个。 I learned from here to check if the javac.exe exists, and that somehow the folder with the java version overrides a similar folder with the javac.exe when installed (yet I couldn't find out how to download and install without that happening).我从这里学到了检查 javac.exe 是否存在,并且在安装时,带有 javac.exe 的文件夹以某种方式覆盖了带有 javac.exe 的类似文件夹(但我无法找到如何在没有发生这种情况的情况下下载和安装) . So I decided to just install the newest version of the JDK.所以我决定只安装最新版本的 JDK。 I checked and there was a javac.exe file in a separate folder, but the update didn't seem to override the previous version.我检查了一下,在一个单独的文件夹中有一个 javac.exe 文件,但更新似乎没有覆盖以前的版本。 Following the guide, I was able to check everything, but the output in the end produced an error about the compiling java not matching the runtime.按照指南,我能够检查所有内容,但最终输出产生了关于编译 java 与运行时不匹配的错误。 I thought of copying the newer java version with the javac.exe to be in the same path of the runtime [the java folder for the newer version was in Program Files like with the guide but the java folder for the original version was in Program Files(x86) to which I had to adapt the environment variables path accordingly], but that didn't fix anything.我想将较新的 java 版本与 javac.exe 复制到运行时的同一路径中 [较新版本的 java 文件夹在 Program Files 中,就像指南一样,但原始版本的 java 文件夹在 Program Files 中(x86) 我不得不相应地调整环境变量路径],但这并没有解决任何问题。 Since I learned that Launch4j could bundle the steps with various versions, I thought of seeing if I could just wrap everything to work in an exe file.自从我了解到 Launch4j 可以将这些步骤与各种版本捆绑在一起,我想看看是否可以将所有内容都包装在一个 exe 文件中。 I was able to produce a file that had no output.我能够生成一个没有输出的文件。 Looking here, someone said they could fix their issue by checking off "console" on the "header" tab instead of "GUI" but the only thing that did for me with the new exe file was open the command prompt to show me nothing.看这里,有人说他们可以通过在“标题”选项卡上选中“控制台”而不是“GUI”来解决他们的问题,但对我来说,新的 exe 文件唯一能做的就是打开命令提示符,什么都不显示。 I am not sure what to check in the command prompt or if I should know it is the same issue as before.我不确定在命令提示符中检查什么,或者我是否应该知道它与以前的问题相同。 Or perhaps Launch4j can work as is but I just don't know what to put in the environment variables (I think I was able to get the exe without a proper input there in the JRE tab since I didn't have a guide this time)?或者 Launch4j 可以按原样工作,但我只是不知道在环境变量中放入什么(我想我能够在 JRE 选项卡中没有正确输入的情况下获取 exe,因为这次我没有指南)? Should I uninstall the previous version even though the command prompt seems to look there or will something else be missing if I do?即使命令提示符看起来在那里,我是否应该卸载以前的版本,或者如果我这样做会丢失其他东西吗?

C:\Users\User>java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) Client VM (build 25.201-b09, mixed mode)

C:\Users\User>javac -version
javac 11.0.2

C:\Users\User>cd C:\JavaTest

C:\JavaTest>java HelloWorld
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError:  HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

C:\JavaTest>

C:\JavaTest>dir
 Volume in drive C has no label.
 Volume Serial Number is 68EF-F43A

 Directory of C:\JavaTest

01/28/2019  12:46 AM    <DIR>          .
01/28/2019  12:46 AM    <DIR>          ..
01/31/2019  12:56 AM               426 HelloWorld.class
01/27/2019  10:41 PM            25,839 HelloWorld.exe
01/25/2019  12:55 AM               751 HelloWorld.jar
01/22/2019  12:29 AM               114 HelloWorld.java
01/25/2019  01:07 AM               798 HelloWorldconverttoexe.xml
01/27/2019  10:41 PM               802 HelloWorldconverttoexe2.xml
01/25/2019  01:09 AM             1,146 launch4j.log
01/28/2019  12:46 AM             5,102 questiontostackoverflow.txt
               8 File(s)         34,978 bytes
               2 Dir(s)  561,260,572,672 bytes free

C:\JavaTest>

Despite the output I got showing a JNI error and the version checks not matching, I thought I could get the proper output manually.尽管输出显示 JNI 错误并且版本检查不匹配,但我认为我可以手动获得正确的输出。 When that didn't work, I expected the "HelloWorld" message (which is what the program code simply is) to appear from creating an exe file with Launch4j, but both attempts resulted in no output when opening the application (the first time didn't even open the command prompt yet the second time briefly did before closing it out).当这不起作用时,我希望使用 Launch4j 创建一个 exe 文件时会出现“HelloWorld”消息(这就是程序代码),但是两次尝试都在打开应用程序时没有输出(第一次没有)甚至没有打开命令提示符,第二次在关闭它之前短暂地做了)。 It seems there is no issue with the actual software and certainly not with the program code, but with the process of running the code after compiling it, and I suppose this continues regardless of the variables for Launch4j.实际软件似乎没有问题,当然也不是程序代码问题,而是编译后运行代码的过程,我想无论 Launch4j 的变量如何,这都会继续。 I feel that having the program folder "JavaTest" separate and directly in the local drive is harmless since none of the guides gave me any reason worry about that.我觉得将程序文件夹“JavaTest”分开并直接放在本地驱动器中是无害的,因为没有一个指南让我有任何理由担心这一点。 I feel if I change anything else, I will make the problem worse.我觉得如果我改变其他任何东西,我会让问题变得更糟。 Specifically, if I uninstall the Java 8 version (which oddly is listed as an update even though I am sure I got the whole JD kit from Oracle), I feel I will lose a different part than the javac.exe, as the command prompt doesn't fully direct to version 11 for everything.具体来说,如果我卸载 Java 8 版本(尽管我确定我从 Oracle 获得了整个 JD 套件,但奇怪的是它被列为更新),我觉得我会丢失与 javac.exe 不同的部分,作为命令提示符并没有完全指向版本 11 的所有内容。 Any help is appreciated.任何帮助表示赞赏。

EDIT: To clarify how I modified my system variables, JAVA_HOME originally had the value to "C:\\Program Files (x86)\\Java\\jre1.8.0_201" with the bin folder missing "javac.exe";编辑:为了阐明我如何修改系统变量,JAVA_HOME 最初的值为“C:\\Program Files (x86)\\Java\\jre1.8.0_201”,而 bin 文件夹缺少“javac.exe”; after installing the newest JDK, I tried both "C:\\Program Files\\Java\\jdk-11.0.2" and "C:\\Program Files (x86)\\Java\\jdk-11.0.2" when copying the "jdk-11.0.2" folder to the same location as the previous version in Program Files (x86), but the command prompt still outputs the older version when I input "java -version";安装最新的 JDK 后,我在复制“jdk-11.0”时尝试了“C:\\Program Files\\Java\\jdk-11.0.2”和“C:\\Program Files (x86)\\Java\\jdk-11.0.2” .2" 文件夹到与 Program Files (x86) 中以前版本相同的位置,但是当我输入 "java -version" 时,命令提示符仍然输出旧版本; the same error is produced when I input "java HelloWorld" from the JavaTest folder in the local drive.当我从本地驱动器的 JavaTest 文件夹中输入“java HelloWorld”时,会产生同样的错误。 The "Path" variable has always started with "Program Files (x86)\\Common Files\\Oracle\\Java..." to which I edit in "%JAVA_HOME%\\bin" with my confidence in the syntax. “路径”变量总是以“Program Files (x86)\\Common Files\\Oracle\\Java...”开头,我在“%JAVA_HOME%\\bin”中编辑,我对语法充满信心。 With this, I can't see how everything can't be found in the newest JDK, including the initial version check in the command prompt, especially when echo %PATH% command does indeed seem to point to the the newest "jdk-11.0.2" version based on the output in the command prompt.有了这个,我看不出在最新的 JDK 中如何找不到所有内容,包括命令提示符中的初始版本检查,尤其是当 echo %PATH% 命令确实似乎指向最新的“jdk-11.0 .2" 版本基于命令提示符中的输出。

EDIT2: I am not sure if using the update feature to either automatically or manually update to 11 instead would've prevented the Java system on the control panel from only recognizing the Java 8 version as it does now, yet even with installing Java 11 from a direct download, I am able to work with the control panel configuration. EDIT2:我不确定使用更新功能自动或手动更新到 11 是否会阻止控制面板上的 Java 系统像现在一样只识别 Java 8 版本,但即使从安装 Java 11直接下载,我可以使用控制面板配置。 On the user side, when I uncheck the path to Java 8 being enabled and add Java 11 paths both from Program Files and from (x86) either with javaw.exe or the whole folder, the command prompt gives the same result.在用户方面,当我取消选中启用 Java 8 的路径并使用 javaw.exe 或整个文件夹从 Program Files 和 (x86) 添加 Java 11 路径时,命令提示符给出相同的结果。 The systems tab does not even allow me to add a path from the Java 11 version yet does allow me to uncheck enabling the Java 8 version (which still makes no difference).系统选项卡甚至不允许我从 Java 11 版本添加路径,但允许我取消选中启用 Java 8 版本(这仍然没有区别)。
I have noticed a couple of other differences with my situation from the guide, though I don't know if it matters.我从指南中注意到我的情况与其他一些差异,尽管我不知道这是否重要。 The guide's user environment variables seem to still include Java in the path yet the only directions for me were to edit the system variables to go to the Java path.该指南的用户环境变量似乎仍然在路径中包含 Java,但对我来说唯一的方向是编辑系统变量以转到 Java 路径。 The output from "dir" in the guide shows everything with the same date, yet "dir" in my command prompt only shows an update to the date of the "HelloWorld.class" file (I have added the output for this edit at the end of the code section of the question), which may make sense as I know the older launch4j attempts would not be affected.指南中“dir”的输出显示日期相同的所有内容,但我的命令提示符中的“dir”只显示“HelloWorld.class”文件日期的更新(我已在问题的代码部分的结尾),这可能是有道理的,因为我知道较旧的 launch4j 尝试不会受到影响。
I am okay with Java 8, but if uninstalling everything and reinstalling Java 8 does not get the javac.exe file, would moving only the javac.exe file of Java 11 to the bin folder of the Java 8 jre folder work (after resetting the paths to Java 8 and finding a way to get rid of the remainder of Java 11)?我对 Java 8 没问题,但是如果卸载所有内容并重新安装 Java 8 没有得到 javac.exe 文件,则只会将 Java 11 的 javac.exe 文件移动到 Java 8 jre 文件夹的 bin 文件夹工作(在重置Java 8 的路径并找到一种方法来摆脱 Java 11 的其余部分)?

check your PATH, you can check the environment variables or run in windows command prompt (CMD)检查您的PATH,您可以检查环境变量或在Windows命令提示符(CMD)中运行

echo %PATH%

you should be pointing only to one JAVA version, I suppose that you are pointing to java 1.8.0_201 and to javac from another java (maybe java 11?).您应该只指向一个 JAVA 版本,我想您指向的是 java 1.8.0_201 和另一个 java(也许是 java 11?)的 javac。

I suppose that you see javac in JDK11 but you do not see javac in JRE8 .我想您在 JDK11 中看到 javac在 JRE8 中没有看到 javac If you want to use Java 8 then download JDK for java 8 and point to It.如果您想使用 Java 8,请下载Java 8 的JDK并指向它。

In case you want java 11, remove links to java 8 in your PATH如果您需要 java 11,请在 PATH 中删除指向 java 8 的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM