java - 为什么 Launch4j 找不到已安装的 JDK?
问题描述
我的计算机上安装了 Launch4j 和 JDK,我正在尝试将 jar 文件转换为 exe。当我启动 Launch4j 时,出现以下错误:
此应用程序需要 Java 运行时环境 1.6.0
我怎样才能解决这个问题?查找已安装 jres/jdks 的 Launch4j 搜索策略是什么?
JDK版本:
java -version
输出:
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, 混合模式, 共享)
我在变量 PATH 和 JAVA_HOME 中都有 JDK 路径。我尝试卸载 JDK 并安装 JRE,但我首先需要使用 javac 命令将 *.java 编译为 *.class 文件。所以在这种情况下,我有不同版本的 JDK 和 JRE。
官方文档说:
Launch4j 需要每个输出可执行文件的 xml 配置文件。
因此,我可以使用带有jdkPreference属性的jre标记在配置文件中指定公共 JRE 或私有 JDK 运行时的首选项。但是如何将其添加到 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>
谢谢
解决方案
您可以使用 jdk 启动 launch4.jar,而不是将 launch4j.exe 作为 Windows 可执行文件启动。因此,在文件资源管理器中标记launch4j.jar,右键单击,选择打开方式,并引用您安装的jdk,例如Open JDK platform binary
推荐阅读
- java - JPA Specification join on fetch 不起作用(Hibernate,Spring Data JPA)
- python-3.x - 测试使用 unittest 呈现 HTML 的烧瓶 enfpoint
- cvxpy - 具有变量依赖性的线性优化
- python - Coinbase API:买卖价格不如现货价格准确
- wso2 - WSO2 Api Manager 4.0 - SOAP 服务作为带有生成 REST API 的 REST API - 请求后端soap的根元素中缺少前缀
- javascript - SVG按钮路径动画
- django - 如何在 Django + PostgreSQL Web 应用程序中更改起始自动生成的主键 ID?
- vue.js - Vue 2 devServer 代理不适用于 websocket
- python - 在请求帖子中发布和接收 URL 作为参数时出错
- c# - 如何在 ASP.NET Core MVC 中读取使用用户名和密码保护的 API