Please help with this initial error. Thanks.

167 views
Skip to first unread message

Vishal Pandya

unread,
Feb 4, 2021, 1:02:04 AM2/4/21
to Byte Buddy
I just started with byte buddy. I get the following error for a simple agent written with Bytebuddy. I have a simple demo application which is spring boot based and trying to run it with a simple java agent code snippet below.

Appreciate a response from members. I couldn't find detailed documentation. Watched videos of the creator, but am still new to it. 
-----------------
public static void premain(String agentArgs, Instrumentation inst) { System.out.println("Agent Loaded"); new AgentBuilder.Default() .with(AgentBuilder.Listener.StreamWriting.toSystemOut()) .type(hasSuperType(named("javax.sql.DataSource"))) .transform((builder, type, classLoader, module) -> builder .visit(Advice.to(VariableAdvice.class).on(isMethod()))).installOn(inst); } 
-------------
 import net.bytebuddy.asm.Advice; 
  public class VariableAdvice { 
  @Advice.OnMethodEnter 
  static void OnEnter() { 
 System.out.println("Hello ByteBuddy"); 
 } 
}
------------

"C:\Program Files\Java\jdk1.8.0_261_deleteword\bin\java.exe" - Exception in thread "main" java.lang.NoClassDefFoundError: net/bytebuddy/dynamic/DynamicType$Builder at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.getDeclaredMethod(Class.java:2128) at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:327) at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) Caused by: java.lang.ClassNotFoundException: net.bytebuddy.dynamic.DynamicType$Builder at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ... 5 more FATAL ERROR in native method: processing of -javaagent failed 
---------------------- 

Vishal Pandya

unread,
Feb 4, 2021, 1:20:56 AM2/4/21
to Byte Buddy
I also tried instrumenting my demo app main class. But get the same error.

public static void premain(String agentArgs, Instrumentation inst) {
System.out.println("Agent Loaded");
new AgentBuilder.Default()
.with(AgentBuilder.Listener.StreamWriting.toSystemOut())
.type(hasSuperType(named("com.abc.DemoApplication")))

.transform((builder, type, classLoader, module) -> builder
.visit(Advice.to(VariableAdvice.class).on(isMethod()))).installOn(inst);
}

Vishal Pandya

unread,
Feb 10, 2021, 11:09:29 AM2/10/21
to Byte Buddy
can please somebody help me? Thanks.

Rafael Winterhalter

unread,
Feb 10, 2021, 1:44:41 PM2/10/21
to Vishal Pandya, Byte Buddy
Did you try what I suggested?

--
You received this message because you are subscribed to the Google Groups "Byte Buddy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to byte-buddy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/byte-buddy/9cd32bc2-ba86-4760-bf63-bbd7405e5a60n%40googlegroups.com.

Vishal Pandya

unread,
Feb 11, 2021, 2:16:37 AM2/11/21
to Byte Buddy

Thank you for the response. But I am must say, you probably are refering to another thread which is not mine. Can please review my case and help? Thanks for your time. Regards.

Vishal Pandya

unread,
Feb 11, 2021, 2:26:39 AM2/11/21
to Byte Buddy
Kindly check below link as well(just in case) where I had posted the question earlier. Thank you.
https://stackoverflow.com/questions/66034766/bytebuddy-java-agent-results-in-noclassdeffound-error 

Vishal Pandya

unread,
Feb 15, 2021, 3:59:11 AM2/15/21
to Byte Buddy
Thanks Rafael for your response. It works now. Regards.
Reply all
Reply to author
Forward
0 new messages