This has to do with a feature of Java called "agents". Have a look at the API documentation of the package java.lang.instrument for more information about this. I've never used that myself before, but it has to do with debugging Java programs. An agent is a special module that you can load when the JVM starts, that can do things to help with debugging or monitoring the application that's going to run in the JVM.
That's not what it's for. There's a better way to accomplish that
While implementing I thought it may not be for this purpose. Since everything worked out, I never bothered too much. What could be the downside of this approach ?
It's non-standard and may confuse whoever looks at the code in the future (you or other developers). It may have undesirable side effects. It may require some additional context or configuration that you can't assume will always be there.
Even if it always functions perfectly, the first reason is enough not to use it given that there are more conventional alternatives.
What are other better ways to accomplish this ?
Hard to say without more context as to how you're executing and what kind of setup you're doing.