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 8029337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:24:22+00:00 2026-06-05T00:24:22+00:00

I use the asm to implements a proxy patterns. for example: the original class

  • 0

I use the asm to implements a proxy patterns.
for example:
the original class is test.service.Service

public class ProxyFactory{
    public static Object generateProxy(Class<?> argument){
        //do generate use asm. 
        //generate a proxyClass that extends argument
        //and override the sayHello() method
        //and than invoke System.out.println("anything") before we call super.sayHello()
        Class<?> class = proxyClass;
        return class.newInstance();
    }
}


public class Service implements IService{
    @Override
    public List<String> sayHello(){
        List<String> list = new ArrayList<String>();
        list.add("stackoverflow user");
        return list;
    }
}

public class Action extends ActionSupport{

     private IService service = ProxyFactory.generateProxy(Service.class);

}

When I request this action than will be an Exception:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
…
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoClassDefFoundError: test.service.Service
at java.lang.ClassLoader.defineClass1(Native Method)
…
… 40 more
Caused by: java.lang.ClassNotFoundException: test.service.Service
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
…
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
… 43 more

It’s seem like tomcat classloader problem because all above code can work if I run it as application could you anybody help me to solve it.
Thank

  • 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-05T00:24:24+00:00Added an answer on June 5, 2026 at 12:24 am

    Solve by myself, actually , As I expected, the problem is caused by classloader.
    this is before code:

    byte[] b = class byte code...
    ClassLoder loader = ClassLoader.getSystemClassLoader();
    Class<?> cls = Class.forName("java.lang.ClassLoader");
    java.lang.reflect.Method method = cls.getDeclaredMethod(
                    "defineClass", new Class[] { String.class, byte[].class,
                            int.class, int.class });
    method.setAccessible(true);
    Object[] args = new Object[] { sc.getName(), b, new Integer(0),
                        new Integer(b.length) };
    clazz = (Class<?>) method.invoke(loader, args);
    

    and now i use Thread.currentThread().getContextClassLoader() to instead of
    ClassLoader.getSystemClassLoader();

    it mean we can use tomcat classloader to defined our class so than can found our web
    application class “test.service.Service”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use Rack::Static, :urls => ['/stylesheets', '/images'], :root => 'public' run proc { |env| [200,
use Service layer to persist data into database. But the Unit Test does not
I've instrumented my class using ASM and processed it like this public class MyClassLoader
Use case: Wanna insert custom annotation to fields in java class generated by JAXB
Use case: class MyTask(Task): queue = 'default_queue' def run(self): # do work Normally I
I am writing a Java Agent which makes use of the Java ASM library
I am attempting to use the Java byte code engineering library ASM to perform
Update : The ClassNotFoundException only occurs if I try to use the web service
I wanted to use ASMifierClassVisitor tool to get the asm code of creating a
I'm trying to use some sort of hibernate object unwrapper/eager fetcher, and beanlib seems

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.