01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: RunWithEngineClassLoader.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.test;
09:
10: import com.uwyn.rife.engine.EngineClassLoader;
11: import java.lang.reflect.Method;
12:
13: /**
14: * Ensures that all the classes in an application are loaded by {@link
15: * EngineClassLoader}, this is needed when continuations are used in elements.
16: * <p>This usage is very simple, you simply prefix your current commandline
17: * with this class. For example:
18: * <pre>java com.uwyn.rife.test.RunWithEngineClassloader my.pakkage.MyMainClass arg1 arg2</pre>
19: * <p>This class will correctly execute your application with the provided
20: * arguments.
21: *
22: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
23: * @version $Revision: 3634 $
24: * @since 1.1
25: */
26: public class RunWithEngineClassLoader {
27: public static void main(String[] args) {
28: ClassLoader classloader = new EngineClassLoader(
29: RunWithEngineClassLoader.class.getClassLoader());
30: Thread.currentThread().setContextClassLoader(classloader);
31:
32: try {
33: if (args != null && args.length > 0) {
34: Class main_class = classloader.loadClass(args[0]);
35: Method main_method = main_class.getMethod("main",
36: new Class[] { String[].class });
37:
38: String[] new_args = new String[args.length - 1];
39: System.arraycopy(args, 1, new_args, 0, args.length - 1);
40:
41: main_method.invoke(null, new Object[] { new_args });
42: }
43: } catch (Throwable e) {
44: throw new RuntimeException(e);
45: }
46: }
47: }
|