简体   繁体   English

在文件夹中搜索jar文件的最新版本,然后从批处理文件运行它

[英]Search for latest version of jar file in folder and run it from batch file

I created a simple batch file to run jar server file. 我创建了一个简单的批处理文件来运行jar服务器文件。 It is two lines of code: 它是两行代码:

cd /D %~dp0
java -jar server-0.17.0.jar

The problem is the server file is updated every while and hence script either fails to run the correct version or fail to run. 问题是服务器文件每次都会更新,因此脚本要么无法运行正确的版本,要么无法运行。

My request is, is there anyway to replace server jar file with latest released by number or date dynamically? 我的要求是,是否可以用数字或日期动态发布最新发布的服务器jar文件?

I'm only aware that I can retrieve available jar files using: 我只知道我可以使用以下方法检索可用的jar文件:

dir *.jar

But have no idea how to concatenate the command with the katest version. 但是不知道如何将命令与katest版本连接起来。 Thanks 谢谢

you can try a script like this: 您可以尝试这样的脚本:

@echo off
for /f "delims=" %%x in ('dir /od /b server*.jar') do set latestjar=%%x
java -jar %latestjar%

Second line in this script will set the latestjar to the last created file whose name compliant with server*.jar template. 该脚本的第二行将把lastjar设置为最后一个名称与server * .jar模板兼容的文件。

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

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