I'm doing a Java Record/Replay tool and I need to launch Java applications from my main Java app. I need access to the EventDispatchThread in order to intercept the events and record them, so I'm launching the application through reflection with (code snippet simplified):
Class<?> app = Class.forName(mainClass);
Method m = app.getMethod("main", new Class[] { String[].class });
m.invoke(null, new Object[] { new String[] {} });
I previously dynamically load all the jars to the classpath and the application is launching almost perfectly.
The problem occurs when the application needs to access any file and does it with relative paths. Because the application is launched through my application the path is not the same as launched from its normal path and the files are not found.
What can I do to solve this problem? dynamically change the execution environment? any ideas?
I would suggest loading your code as a "Java Agent" whilst starting the target application.
(With your method you will also find that the system class loader is wrong.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With