How to find where a method is defined at runtime?

This is really late, but here’s how you can find where a method is defined: http://gist.github.com/76951 # How to find out where a method comes from. # Learned this from Dave Thomas while teaching Advanced Ruby Studio # Makes the case for separating method definitions into # modules, especially when enhancing built-in classes. module Perpetrator … Read more

Adding files to java classpath at runtime [duplicate]

You can only add folders or jar files to a class loader. So if you have a single class file, you need to put it into the appropriate folder structure first. Here is a rather ugly hack that adds to the SystemClassLoader at runtime: import java.io.IOException; import java.io.File; import java.net.URLClassLoader; import java.net.URL; import java.lang.reflect.Method; public … Read more

How do you modify the web.config appSettings at runtime?

You need to use WebConfigurationManager.OpenWebConfiguration(): For Example: Dim myConfiguration As Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(“~”) myConfiguration.ConnectionStrings.ConnectionStrings(“myDatabaseName”).ConnectionString = txtConnectionString.Text myConfiguration.AppSettings.Settings.Item(“myKey”).Value = txtmyKey.Text myConfiguration.Save() I think you might also need to set AllowLocation in machine.config. This is a boolean value that indicates whether individual pages can be configured using the element. If the “allowLocation” is false, it cannot be … Read more

How to load a jar file at runtime [duplicate]

Reloading existing classes with existing data is likely to break things. You can load new code into new class loaders relatively easily: ClassLoader loader = URLClassLoader.newInstance( new URL[] { yourURL }, getClass().getClassLoader() ); Class<?> clazz = Class.forName(“mypackage.MyClass”, true, loader); Class<? extends Runnable> runClass = clazz.asSubclass(Runnable.class); // Avoid Class.newInstance, for it is evil. Constructor<? extends Runnable> … Read more

Java Runtime.getRuntime(): getting output from executing a command line program

Here is the way to go: Runtime rt = Runtime.getRuntime(); String[] commands = {“system.exe”, “-get t”}; Process proc = rt.exec(commands); BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); // Read the output from the command System.out.println(“Here is the standard output of the command:\n”); String s = null; while ((s = stdInput.readLine()) … Read more

Remove Top-Level Container on Runtime

Invoking dispose() allows the host platform to reclaim memory consumed by the heavyweight peer, but it can’t do so until after the WINDOW_CLOSING event is processed on the EventQueue. Even then, gc() is a suggestion. Addendum: Another way to see the nightmare is via a profiler. Running the example below with jvisualvm, one can see … Read more