[Question] Finding my rt.jar and telling javassist where it is
marceloslacerda opened this issue · 1 comments
marceloslacerda commented
I'm trying to make a an agent that injects some code into a jdbc class at runtime in a running tomcat.
The code I'm using to inject my stuff is
ctMethod.insertAfter("System.out.printf(\"JobID: %d\\\n\", cacheJobNumber);")
However I'm getting an error stating that printf not found in java.io.PrintStream
javassist.CannotCompileException: [source error] printf(java.lang.String,java.lang.String) not found in java.io.PrintStream
at javassist.CtBehavior.insertAfter(CtBehavior.java:970)
Since I'm running a springboot app (which its running inside an embedded tomcat) it seems like the classpath
isn't being filled with any jars.
Here's how I'm trying to populate the ClassPool
val classPool: ClassPool = ClassPool.getDefault()
classPool.appendPathList(ManagementFactory.getRuntimeMXBean().classPath)
LOGGER.warning("Class path from ManagementFactory ${ManagementFactory.getRuntimeMXBean().classPath}")
val classClassPath = ClassClassPath(this.javaClass)
LOGGER.warning("Class path from ClassClassPath ${classClassPath.toString()}")
classPool.insertClassPath(classClassPath);
Unfortunately neither ManagementFactory
nor ClassClassPath
is able to provide rt.jar
Do you guys have some suggestion on what should I try?
I'm using:
- kotlin 1.7.10
- javassist 3.29.1-GA
- java 11.0.16 (targeting java 8)
marceloslacerda commented
The issue solved itself when I used the same jvm for the agent and the tomcat application