コード例 #1
0
 /**
  * Loads a class and calls <code>main()</code> in that class.
  *
  * @param classname the loaded class.
  * @param args parameters passed to <code>main()</code>.
  */
 public void run(String classname, String[] args) throws Throwable {
   Class c = loadClass(classname);
   try {
     c.getDeclaredMethod("main", new Class[] {String[].class}).invoke(null, new Object[] {args});
   } catch (java.lang.reflect.InvocationTargetException e) {
     throw e.getTargetException();
   }
 }
コード例 #2
0
ファイル: JvstTest2.java プロジェクト: romix/javassist
  private void testDotClass2(String cname, boolean java5) throws Exception {
    CtClass cc = sloader.makeClass(cname);
    CtClass cc3 = sloader.makeClass("test2.DotClass3");
    if (java5) cc.getClassFile2().setVersionToJava5();

    CtMethod m =
        CtNewMethod.make(
            "public int test() {" + "  return test2.DotClass3.class.getName().length(); }", cc);
    cc.addMethod(m);
    cc.writeFile();
    // don't execute cc3.writeFile();
    Object obj = make(cc.getName());
    try {
      assertEquals(15, invoke(obj, "test"));
    } catch (java.lang.reflect.InvocationTargetException e) {
      Throwable t = e.getCause();
      assertTrue(t instanceof java.lang.NoClassDefFoundError);
    }
  }