title: loading another class with javassist
body: <p>I have two projects: a profiler and a basic application (with JUnit tests)</p>
  
  <p>The profiler uses Javassist to instrument the basic application. </p>
  
  <p>When the profiler is inside the basic application, it works fine.
  When the profiler is outside the basic application, I have to import the basic application jar file into the build path on Eclipse to be abble to instrument my application.</p>
  
  <p>I want to run my profiler on my basic application in command line as EMMA does:</p>
  
  <blockquote>
    <blockquote>
      <p>java -jar profiler.jar run application.jar</p>
    </blockquote>
  </blockquote>
  
  <p>But I don't know how to tell my profiler, ok, instrument this jar.</p>
  
  <p>Here is my profiler main code:</p>
  
  <pre><code>    public static void main(String[] args) throws Exception {   
      Loader loader = new Loader();
      loader.addTranslator(ClassPool.getDefault(), new Profiler());
      try {
          loader.run("com.application.bookstore.test.Test", null);
      } catch (Throwable e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I tried to do that:</p>
  
  <pre><code>final String arg = args[0];
  final String[] commandArgs = new String[args.length - 1];
  System.arraycopy(args, 1, commandArgs, 0, commandArgs.length-1);
  
  loader.run(arg, commandArgs);
  </code></pre>
  
  <p>But when I run it, I get:</p>
  
  <pre><code>[kdelemme@pdkdelemme build]$ java -jar profiler.jar bookstore.jar
  java.lang.ClassNotFoundException: bookstore.jar
      at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
      at javassist.Loader.delegateToParent(Loader.java:429)
      at javassist.Loader.loadClass(Loader.java:315)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
      at javassist.Loader.run(Loader.java:289)
      at com.modeln.Profiler.main(Profiler.java:93)
  </code></pre>
  
  <p>So I tried to run directly into my Main class directory:</p>
  
  <pre><code>[kdelemme@pdkdelemme test]$ ls
  profiler.jar  Test.class
  [kdelemme@pdkdelemme test]$ java -jar profiler.jar Test 
  java.lang.NoClassDefFoundError: Test (wrong name: com/application/bookstore/test/Test)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:480)
      at javassist.Loader.findClass(Loader.java:380)
      at javassist.Loader.loadClass(Loader.java:312)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
      at javassist.Loader.run(Loader.java:289)
      at com.modeln.Profiler.main(Profiler.java:93)
  </code></pre>
  
  <p>So Have you any ideas to how run my profiler on an outside jar project? Thanks a lot!</p>