MyFile.jar 파일이 있습니다. jar 파일을 검색하여 트리거하는 배치 파일이 필요합니다.시스템의 모든 위치에있는 jar 파일을 실행하는 배치 파일을 작성하는 방법
다음 해결책을 찾았습니다. 하지만 배치 파일과 jar 파일은 같은 폴더에 있어야합니다.
java -jar %~dp0MyFile.jar %*
클라이언트가 시스템에 jar 파일을 둘 위치를 알 수 없습니다. 하지만 그들은 배치 폴더에 배치 파일을 넣을 것입니다.
편집 : 지금이 배치 파일을 작성했습니다.
`ECHO
ECHO Locating the Jar
IF EXIST java -jar MyFile.jar ELSE (GOTO
SearchJar)
:SearchJar
SET the_path=D: & CD\
DIR /S/B File.jar > installer_location.txt
SET /P the_path=< installer_location.txt
if defined the_path goto :FoundIt
E: & CD\
DIR /S/B MyFile.jar > installer_location.txt
SET /P the_path=< installer_location.txt
if defined the_path goto :FoundIt
C: & CD\
DIR /S/B MyFile.jar > installer_location.txt
SET /P the_path=< installer_location.txt
if defined the_path goto :FoundIt
G: & CD\
DIR /S/B MyFile.jar > installer_location.txt
SET /P the_path=< installer_location.txt
if defined the_path goto :FoundIt
H: & CD\
DIR /S/B MyFile.jar > installer_location.txt
SET /P the_path=< installer_location.txt
if defined the_path goto :FoundIt
I: & CD\
DIR /S/B MyFile.jar > installer_location.txt
SET /P the_path=< installer_location.txt
if defined the_path goto :FoundIt
ECHO Jar not found.
:FoundIt
ECHO Jar file found at %the_path%
CALL java -jar %the_path%`
현재 내 시스템에서 작동합니다. 그러나 모든 드라이브를 한꺼번에 검사하는 간단한 방법이 있는지 확실하지 않습니다.
이는 합당한 요청이 아닙니다. 클라이언트가 배치 폴더에 배치 파일을 배치하도록 요구하는 경우 jar 파일을 시작 폴더에 배치하지 않아도됩니다. 배치 파일을 사용하면 파일 시스템에서 jar 파일의 위치, 환경 변수에 의한 파일 시스템 검색 (매우 느림) 또는 특정 위치에 있어야하는 Jar 파일 위치를 알아야합니다. 가장 좋은 방법은 InstallShield와 같은 설치 소프트웨어를 사용하는 것입니다. – gknicker
배치 파일이있는 곳에 jar 파일을 넣으면 '% ~ dp0'는 배치 파일이있는 디렉토리로 평가되기 때문에 게시 한 코드가 작동합니다. 그러나 큰 따옴표로 묶어야합니다 :' "% ~ dp0MyFile .jar "디렉토리에 공백이있을 경우를 대비하여. –
시스템에서 jar 파일을 검색하여 실행하는 배치 파일을 만들 수 없습니까? 내 질문에 언급 한 것처럼, java -jar % ~ dp0MyFile.jar % * (배치 파일의) 위치를 검색하고 배치 파일 위치의 경로를 변경하고 jar 파일을 실행합니다. jar 파일에 대한 배치 파일을 만들 수있는 방법이 있습니까? – Jenny