简体   繁体   English

如何通过批处理获取最新版本的Java

[英]How to get Most Recent Version of Java Through Batch

I have to create a batch program that verifies a correct JDK install. 我必须创建一个批处理程序来验证正确的JDK安装。 I have already created a simple java program that, when run, outputs conformation that the JDK has been installed. 我已经创建了一个简单的Java程序,该Java程序在运行时会输出已安装JDK的配置。 The program must also, however, set the path to the new JDK. 但是,该程序还必须设置新JDK的路径。 I know that the java file will be in c:\\Program Files\\java\\jdk1.8.0_##\\bin , where ## is one of about 10 diffrent numbers. 我知道Java文件将位于c:\\Program Files\\java\\jdk1.8.0_##\\bin ,其中##是大约10个不同数字之一。 Is there any way I can search the directory c:\\Program Files\\java for folders beginning with jdk1.8.0 such that I could set a variable to the appropriate filename? 有什么办法可以在目录c:\\Program Files\\java搜索以jdk1.8.0开头的文件夹, jdk1.8.0可以将变量设置为适当的文件名? There are other files in the c:\\Program Files\\java directoy, including previous JDKs and JREs. c:\\Program Files\\java Directoy中还有其他文件,包括以前的JDK和JRE。

echo Initializing...
set current=%cd% //get current directory
cd c:\Program Files\java //navigate to java directory
set java= //Files formated jdk1.8.0_...
cd %current% //return directory to local (JavaDemo is located here)
set path=%java% //Set path for javac
javac JavaDemo.java //compile JavaDemo
java JavaDemo //run JavaDemo

Thanks in advance! 提前致谢! Know you guys are a huge help 知道你们有很大的帮助

You could use the dir command with sort options : dir command 您可以将dir命令与sort选项一起使用: dir命令

and go through the results with : 并通过以下结果查看结果:

for /F %%x in ('dir /B/D %MYDIR%') do ( set PATH=%MYDIR%)

and choose the right one with a if statement 然后用if语句选择合适的

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

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