Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8079357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:04:32+00:00 2026-06-05T16:04:32+00:00

I have two projects: a profiler and a basic application (with JUnit tests) The

  • 0

I have two projects: a profiler and a basic application (with JUnit tests)

The profiler uses Javassist to instrument the basic application.

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.

I want to run my profiler on my basic application in command line as EMMA does:

java -jar profiler.jar run application.jar

But I don’t know how to tell my profiler, ok, instrument this jar.

Here is my profiler main 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();
    }
}

I tried to do that:

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);

But when I run it, I get:

[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)

So I tried to run directly into my Main class directory:

[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)

So Have you any ideas to how run my profiler on an outside jar project? Thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:04:33+00:00Added an answer on June 5, 2026 at 4:04 pm

    Ok, here’s the solution: Just pool.insertClassPath()

    public static void main(String[] args) throws Exception {   
        Loader loader = new Loader();
        loader.addTranslator(ClassPool.getDefault(), new Profiler());
        try {
            if (args.length < 1) {
                System.out.println(TOOL_USAGE);
            } else {
    
                //Initialize profiler with config/config.properties file
                initializeProfiler();
    
                final String[] commandArgs = new String[args.length - 1];
                System.arraycopy(args, 1, commandArgs, 0, commandArgs.length);
    
                //Open a jar file, unJar it into /tmp/ then add the /tmp/ classpath to the javassist laoder
                File file = new File(args[0]);
                JarFile jarFile = new JarFile(args[0]);
                Manifest manifest = jarFile.getManifest();
                String mainClassName = null;
    
                if (manifest != null) {
                    mainClassName = manifest.getMainAttributes().getValue("Main-Class");
                }
    
                jarFile.close();
    
                mainClassName = mainClassName.replaceAll("/", ".");
                //Default temp directory is Jarfilename without .jar
                final File workDir = File.createTempFile(args[0].substring(0, args[0].indexOf('.')), "");
                workDir.delete();
                workDir.mkdirs();
    
                //Unjar all files into WorkDir temp directory
                unJar(file, workDir);
    
                //Add all directories into classPath
                createClassPath(workDir, file);
    
                //Add the classPath with unJar files into the Javassist ClassPool
                ClassPool pool = ClassPool.getDefault();
                pool.insertClassPath(workDir + "/");
                loader.run(mainClassName, null);
    
              }
    
        } catch (Throwable e) {
            e.printStackTrace();
        }
    
        System.out.println("Instrumentation of " + args[0] + " finished.");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two maven profiles for running projects web tests: 1. first
I have two projects, a Cocoa iPhone application and a static library which it
I have two projects FOO and BAR Inside of BAR i have a class
I have two projects and I want to combine them together.When I install each
I have two projects A and B both are built differently, but the jars
I have two projects with similar starting splash and menu activities, but the package
I have two projects.One project is build in MVC asp.net and the other project
I have two projects in the same server, their settings conflict in the session.auto_start,
I have two projects in my Solution. One implements my business logic and has
I have two projects in my solution   1- asp.net web project.   2-

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.