byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

java.lang.NoClassDefFoundError: net/bytebuddy/agent/builder/AgentBuilder$Default

Open xzy-max1 opened this issue 3 years ago • 1 comments

code: public class ToStringAgent { public static void premain(String arguments, Instrumentation instrumentation) { new AgentBuilder.Default() .type(isAnnotatedWith(ToString.class)) .transform(new AgentBuilder.Transformer() { @Override public DynamicType.Builder> transform(DynamicType.Builder> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) { return builder.method(named("toString")) .intercept(FixedValue.value("transformed")); }

}).installOn(instrumentation);

} }

error: Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source) Caused by: java.lang.NoClassDefFoundError: net/bytebuddy/agent/builder/AgentBuilder$Default at com.fcbox.delay.queue.bytecode.ToStringAgent.premain(ToStringAgent.java:17) ... 6 more desc: The error I use this cmd that java -javaagent:.\delay-queue-1.4.1-SNAPSHOT.jar com.fcbox.delay.queue.bytecode.Example occur.

xzy-max1 avatar Jun 09 '22 02:06 xzy-max1

Did you create your agent as a fat jar? It seems like Byte Buddy is missing in it.

raphw avatar Jun 09 '22 06:06 raphw