简体   繁体   English

JAVA:如何使 java EXE 在不同的 PC 上运行

[英]JAVA: How to make java EXE run on different PCs

I created mini project on Java.我在 Java 上创建了迷你项目。 Using Eclipse I converted my project to.JAR and later.JAR to.EXE using launch4j 3.12.使用 Eclipse 我将我的项目转换为.JAR 及更高版本。JAR 使用 launch4j 3.12 转换为.EXE。 On my PC exe work correct.我的 PC上,exe 工作正常。 But if I share my file to my friends which, File give a error:但是如果我将我的文件分享给我的朋友,文件会报错:

"A JNI Error has occurred, please check your installation and try again". “发生 JNI 错误,请检查您的安装并重试”。

And in launch4j's console print:在 launch4j 的控制台打印中:

"Exception in thread "main" java.lang.UnsupportedClassVersionError: Game has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 52.0". "Exception in thread "main" java.lang.UnsupportedClassVersionError: Game has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 52.0".

But I specified the path to jre.但是我指定了jre的路径。 How can I fix this problem and launch my Java Project on my friends PCs?如何解决此问题并在我朋友的 PC 上启动我的 Java 项目? My launch4j config:我的launch4j配置:

<?xml version="1.0" encoding="UTF-8"?>
    <launch4jConfig>
    <dontWrapJar>false</dontWrapJar>
    <headerType>gui</headerType>
    <jar>C:\Users\Admin\Desktop\JavaProject\JARFile.jar</jar>
    <outfile>C:\Users\Admin\Desktop\JavaProject\game.exe</outfile>
    <errTitle></errTitle>
    <cmdLine></cmdLine>
    <chdir>.</chdir>
    <priority>normal</priority>
    <downloadUrl>http://java.com/download</downloadUrl>
    <supportUrl></supportUrl>
    <stayAlive>false</stayAlive>
    <restartOnCrash>false</restartOnCrash>
    <manifest></manifest>
    <icon></icon>
    <jre>
        <path>javafiles/jre</path>
        <bundledJre64Bit>true</bundledJre64Bit>
        <bundledJreAsFallback>true</bundledJreAsFallback>
        <minVersion>1</minVersion>
        <maxVersion></maxVersion>
        <jdkPreference>preferJre</jdkPreference>
        <runtimeBits>64/32</runtimeBits>
   </jre>
</launch4jConfig>

the problem is that your program requires at least java version 59 (java 15) while on your friends computers only java version 52 (java 8) is installed.问题是您的程序至少需要 java 版本 59 (java 15) 而在您的朋友计算机上只安装 java 版本 52 (java 8)。

so there are two solutions:所以有两种解决方案:

  • compile with older java version if you do not need newer language features如果您不需要较新的语言功能,请使用较旧的 java 版本进行编译
  • upgrade to java 15 jre/jdk on your friends computers that want to run your program在您想要运行您的程序的朋友计算机上升级到 java 15 jre/jdk

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

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