I need to add an instrumentation JAR to my Java command line. If possible, I want to this argument to reference a JAR included in my Maven dependencies. As an example:
java -javaagent:tooling.jar -jar myapplication.jar
This "tooling.jar" does not exist as an explicit file in the filesystem. Instead, it is listed as a runtime dependency in Maven:
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>tooling</artifactId>
<scope>runtime</scope>
</dependency>
If it's relevant, I'm using Java 11 and Spring Boot.
The purpose of this is to avoid having to move two separate JAR files to every run environment (for technical reasons I am only able to deploy the application JAR). As far as I can tell there's nothing technically wrong with this approach, as the JAR does exist - it is just wrapped into the application JAR. However, nowhere that I've found has described this process, so I wonder if I'm doing something terribly wrong. I haven't been able to test this yet. Is this a valid pattern and what is the appropriate syntax for it?