简体   繁体   English

为什么 Launch4j 找不到已安装的 JDK?

[英]Why Launch4j does not find installed JDK?

I have Launch4j and JDK installed on my computer and I am trying to convert jar-file to exe.我在我的电脑上安装了 Launch4j 和 JDK,我正在尝试将 jar 文件转换为 exe。 When I start Launch4j I get the following error:当我启动 Launch4j 时,出现以下错误:

This application requires a Java Runtime Environment 1.6.0此应用程序需要 Java 运行时环境 1.6.0

How can I fix this?我怎样才能解决这个问题? What is the Launch4j search strategy to find installed jres/jdks?查找已安装的 jres/jdks 的 Launch4j 搜索策略是什么?

JDK version: JDK版本:

java -version

Output: Output:

java version "14" 2020-03-17 Java(TM) SE Runtime Environment (build 14+36-1461) Java HotSpot(TM) 64-Bit Server VM (build 14+36-1461, mixed mode, sharing) java 版本“14” 2020-03-17 Java(TM) SE 运行时环境(build 14+36-1461) Java HotSpot(TM) 64 位服务器 VM(build 14+36-1461,混合模式,共享)

I have JDK-path in both variables PATH and JAVA_HOME.我在变量 PATH 和 JAVA_HOME 中都有 JDK 路径。 I tried to uninstall the JDK and install JRE, but I first need to compile *.java to *.class files with the javac command.我尝试卸载JDK并安装JRE,但我首先需要使用javac命令将*.java编译成*.class文件。 So in this case I have different versions of JDK and JRE.所以在这种情况下,我有不同版本的 JDK 和 JRE。

The official documentation says:官方文档说:

Launch4j requires an xml configuration file for each output executable. Launch4j 需要每个 output 可执行文件的 xml 配置文件。

So I can use jre tag with jdkPreference attribute to specify a preference for a public JRE or a private JDK runtime in configuration file.因此,我可以使用带有jdkPreference属性的jre标记在配置文件中指定公共 JRE 或私有 JDK 运行时的首选项。 But how can I add this to build.xml file?但是如何将它添加到 build.xml 文件中呢?

build.xml:构建.xml:

<project name="launch4j" default="compile" basedir=".">
    <property name="src" location="src" />
    <property name="lib" location="lib" />
    <property name="build" location="build" />
    <property name="jar" location="./${ant.project.name}.jar" />
    <property name="launch4j.dir" location="." />
    <property name="maven" location="maven" />

    <path id="dist.classpath">
        <pathelement path="${build}" />
        <fileset dir="${lib}">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <target name="init">
        <tstamp />
        <mkdir dir="${build}" />
    </target>

    <target name="compile" depends="init" description="compile the source">
        <javac srcdir="${src}" destdir="${build}" classpathref="dist.classpath" source="1.6" debug="on" includeantruntime="false" />
        <copy todir="${build}/images">
            <fileset dir="${src}/images">
                <include name="**/*" />
            </fileset>
        </copy>
        <copy todir="${build}">
            <fileset dir="${src}">
                <include name="**/*.properties" />
            </fileset>
        </copy>
    </target>

    <target name="jar" depends="compile" description="create jar">
        <fileset dir="${lib}" id="lib.dist.fileset">
            <include name="**/*.jar" />
        </fileset>
        <pathconvert pathsep=" " property="dist.classpath" refid="lib.dist.fileset">
            <map from="${lib}" to="./lib" />
        </pathconvert>
        <!-- Put everything in ${build} into a jar file -->
        <jar jarfile="${jar}">
            <fileset dir="${build}" excludes="**/messages_es.properties" />
            <manifest>
                <attribute name="Main-Class" value="net.sf.launch4j.Main" />
                <attribute name="Class-Path" value=". ${dist.classpath}" />
            </manifest>
        </jar>
    </target>

    <target name="demo" depends="jar" description="build the demos">
        <ant dir="./demo/ConsoleApp" inheritAll="false" />
        <ant dir="./demo/SimpleApp" inheritAll="false" />
    </target>

    <target name="clean" description="clean up">
        <delete dir="${build}" />
        <delete file="${jar}" />
        <ant dir="./demo/ConsoleApp" target="clean" inheritAll="false" />
        <ant dir="./demo/SimpleApp" target="clean" inheritAll="false" />
    </target>

    <target name="switch-to-maven" description="switch project to maven">
        <copy todir="." overwrite="true">
            <fileset dir="${maven}">
                <include name="**/*" />
            </fileset>
        </copy>
        <delete dir="${lib}" />
        <mkdir dir="./target" />
    </target>
</project>

Thanks谢谢

Launch4j seems to be limited with new java versions... In last update they shows up a detailed info about supported jvm, the last one is 1.8.9 and there is a ticket about compliance with java 9 and later... changelog and tickets launch4j Launch4j 似乎受到新 Java 版本的限制...在上次更新中,他们显示了有关受支持的 jvm 的详细信息,最后一个是 1.8.9,并且有一张关于符合 Java 9 及更高版本的票证...变更日志和票证启动4j

带有消息的 Launch4j 弹出窗口

Instead of starting the launch4j.exe as windows executable, you may start the launch4.jar with your jdk.您可以使用 jdk 启动 launch4.jar,而不是将 launch4j.exe 作为 Windows 可执行文件启动。 Therefore, mark the launch4j.jar in the file explorer, right click, choose open with, and reference your installed jdk, eg Open JDK platform binary因此,在文件资源管理器中标记launch4j.jar,右键单击,选择打开方式,并引用您安装的jdk,例如Open JDK platform binary

Install Oracle's JRE to get Launch4j to work.安装 Oracle 的 JRE 以使 Launch4j 工作。

Launch4j has limited recognition for versions and providers of the JVM. I had only AdoptOpenJDK 1.8 installed, and Launch4j's exe didn't work. Launch4j 对 JVM 的版本和提供者的识别有限。我只安装了 AdoptOpenJDK 1.8,Launch4j 的 exe 没有运行。 When I installed Oracle's JRE 1.8, then it launched my jar application without any problems.当我安装 Oracle 的 JRE 1.8 时,它会毫无问题地启动我的 jar 应用程序。

Even though I was getting the Java 1.6 Error message, I was still sure the jar application worked with Java 1.8.即使我收到 Java 1.6 错误消息,我仍然确定 jar 应用程序可以与 Java 1.8 一起使用。 I think it was due to Launch4j being stale and not under recent updates at the time I integrated it into my application.我认为这是由于 Launch4j 已过时,并且在我将其集成到我的应用程序时没有进行最新更新。

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

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