Grabbing apk file without using an absolute path

I’m using appium/java/maven for some automated tests for an app. Currently I’m just grabbing the apk location via absolute path in my project:

cap.setCapability(MobileCapabilityType.APP, "D:\\abs\\path\\src\\main\\resources\\testapp.apk");

This works locally, but I need to be able to execute this a different machine (via mvn commands), so this won’t work. I read online to grab the apk file from compiled class folder (target/classes/testapp.apk), which I did below:

ClassLoader classLoader = getClass().getClassLoader();
File apkFile = new File(classLoader.getResource("testapp.apk").getFile());

But when I run I get an error:

        org.openqa.selenium.json.JsonException: Unable to determine type from: D. Last 41 characters read: {
          "desiredCapabilities": {
            "app": D

Error seems to me like it has part of the path (my local drive for this is D) but something is wrong with the full path.

Anyone have any ideas here? Am I mising something? Or is there a better approach for this?

Thanks!

The way I would approach this is to use a java properties file, and include it in .gitignore so that you don’t commit it to the repo. That way you just set the path for the machine you are working on and change it when you set up on another. Here’s a tutorial on java properties file:

https://mkyong.com/java/java-properties-file-examples/