gpt4 book ai didi

java - 检索Windows批处理文件中文件夹的绝对路径

转载 作者:行者123 更新时间:2023-12-01 12:58:34 25 4
gpt4 key购买 nike

我有一个文件夹,其中包含批处理文件、jar 文件和 JRE。批处理文件应该通过调用 JRE 来运行 jar。我知道它会是这样的:

   <jre-path>/bin/java.exe -jar <jar-path>Executable.jar

在批处理文件中,我如何检索包含所有这些 jar 和 jre 的文件夹的绝对路径?对于这个问题有一个答案:what is the current directory in batch file建议使用 %~dp0 ,但是我如何以正确的方式使用它来执行上面提到的命令?

最佳答案

首先确定 jar 和运行脚本之间的相对路径。该脚本将使用您已经提到的答案来检测其位置。 (%~dp0给出目录)

mydir=%~dp0 
jardir=%mydir%/
..
java.exe -jar %jardir%/exectuble.jar

另一种方法是使用像 launch4j enter link description here 这样的产品。您可以从变量访问安装位置,为用户提供漂亮的启动图标,在打包中包含 jre 等等。

关于java - 检索Windows批处理文件中文件夹的绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23693134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com