diff --git a/tests/copy-bin.bat b/tests/copy-bin.bat index e69a1ec..8df78a9 100644 --- a/tests/copy-bin.bat +++ b/tests/copy-bin.bat @@ -1,4 +1,30 @@ @ECHO OFF +SETLOCAL -cp ../build/bin/*.dll ./resources -cp ../build/bin/*.exe ./resources \ No newline at end of file +REM Always operate relative to this script so it works from any working directory. +PUSHD "%~dp0" + +IF NOT EXIST "resources" MKDIR "resources" + +REM Copy fresh build artifacts into the test resources directory. +COPY /Y "..\build\bin\*.dll" "resources" >NUL +IF ERRORLEVEL 1 ( + ECHO [ERROR] Failed to copy DLLs from ..\build\bin to resources. + ECHO Make sure the project is built and that no test JVM is still + ECHO holding resources\libagent.dll open. + POPD + EXIT /B 1 +) + +COPY /Y "..\build\bin\*.exe" "resources" >NUL +IF ERRORLEVEL 1 ( + ECHO [ERROR] Failed to copy EXEs from ..\build\bin to resources. + ECHO Make sure the project is built before running this script. + POPD + EXIT /B 1 +) + +ECHO [SUCCESS] Copied build binaries to tests\resources. + +POPD +EXIT /B 0 diff --git a/tests/src/GetClassBytesByName.java b/tests/src/GetClassBytesByName.java index 2535fc2..1fd590c 100644 --- a/tests/src/GetClassBytesByName.java +++ b/tests/src/GetClassBytesByName.java @@ -2,13 +2,16 @@ import cn.xiaozhou233.juiceagent.api.JuiceAgent; import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; public class GetClassBytesByName { - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws Exception { System.load(new File("resources/libagent.dll").getAbsolutePath()); JuiceAgent.init(""); + // getClassBytesByName only resolves classes that are already loaded, + // so make sure the target class is loaded before looking it up. + Class.forName("Target"); + String className = "Target"; byte[] bytes = JuiceAgent.getClassBytesByName(className);