gpt4 book ai didi

java - 如何通过 .bat 文件将参数传递给另一个 Java 程序?

转载 作者:行者123 更新时间:2023-12-01 18:16:55 24 4
gpt4 key购买 nike

我有一个关于使用评估程序通过批处理文件访问代码来评估我的代码的问题。我已粘贴下面的批处理文件代码。

@if "%DEBUG%" == "" @echo off
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%..

@rem Add default JVM options here. You can also use JAVA_OPTS and TASK_SMALLEST_POLYGON_EVALUATOR_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
echo %JAVA_EXE%
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
echo %JAVA_HOME%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=D:\Programs\Java\programming\Polygon\bin\testerexec.jar
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=D:\Programs\Java\programming\Polygon\bin\testerexec.jar

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\lib\task-smallest-polygon-evaluator.jar;%APP_HOME%\lib\scala-logging_2.13-3.9.2.jar;%APP_HOME%\lib\jackson-module-scala_2.13-2.10.2.jar;%APP_HOME%\lib\scallop_2.13-3.3.2.jar;%APP_HOME%\lib\scala-reflect-2.13.0.jar;%APP_HOME%\lib\scala-library-2.13.1.jar;%APP_HOME%\lib\logback-classic-1.2.3.jar;%APP_HOME%\lib\jackson-module-paranamer-2.10.2.jar;%APP_HOME%\lib\jackson-databind-2.10.2.jar;%APP_HOME%\lib\logback-core-1.2.3.jar;%APP_HOME%\lib\slf4j-api-1.7.26.jar;%APP_HOME%\lib\jackson-annotations-2.10.2.jar;%APP_HOME%\lib\jackson-core-2.10.2.jar;%APP_HOME%\lib\paranamer-2.8.jar
echo %JAVA_OPTS%
echo %TASK_SMALLEST_POLYGON_EVALUATOR_OPTS%
echo done
@rem Execute task-smallest-polygon-evaluator
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %TASK_SMALLEST_POLYGON_EVALUATOR_OPTS% -classpath "%CLASSPATH%" com.simscale.smallestpolygon.Evaluator %CMD_LINE_ARGS%
pause
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable TASK_SMALLEST_POLYGON_EVALUATOR_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%TASK_SMALLEST_POLYGON_EVALUATOR_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega

有一个评估器需要评估我的代码。我想知道如何将参数传递给这个批处理文件。我尝试在参数中输入 .jar 文件的位置,但收到错误

java.io.IOException: Cannot run program "D:\Programs\Java\programming\Polygon\bin\testerexec.jar": CreateProcess error=193, %1 is not a valid Win32 application

ERROR com.simscale.util.Util$ - unexpected exception in threadjava.io.IOException: Cannot run program "java -jar "D:\New folder\task-smallest-polygon-evaluator\bin\testerexec3.jar"": CreateProcess error=2, The system cannot find the file specified

我在输入中尝试了两种参数,但似乎都不起作用

An evaluator program is supplied. This program receives one positional argument, which is theexecutable file (entry point for the target program – your program).

我传递的位置参数产生错误。有人可以帮助我如何通过这个立场争论吗?bat 文件中必须给出哪些输入?

最佳答案

首先尝试将其安装为窗口服务并运行该服务。

使用此链接下载 nssm:https://nssm.cc/release/nssm-2.24.zip然后,首先将 .jar 文件安装为 Windows 服务。作为服务安装的示例代码:nssm install serviceName url-to-java-exec url-to-Jar-file

希望这对您有帮助

关于java - 如何通过 .bat 文件将参数传递给另一个 Java 程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60348024/

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