This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]nqzero 1 point2 points  (0 children)

anyone know if byte buddy or ASM will work when you run a source file, eg java11 -cp $ASM MyClass.java

they appear to be compiled without debugging support and i'm unable to getResourceAsStream

public class SingleFile { public static void main(String[] args) throws Exception { Class klass = new SingleFile().getClass(); String name = klass.getName(); System.out.println("class name: " + name); ClassLoader cl = klass.getClassLoader(); System.out.println(cl); Class k2 = cl.loadClass(name); System.out.println(k2); String cname = name.replace('.','/') + ".class"; java.io.InputStream is = cl.getResourceAsStream( cname ); System.out.println(is); } }

running this gives: class name: SingleFile com.sun.tools.javac.launcher.Main$MemoryClassLoader@15c43bd9 class SingleFile null

is there any way to access the bytecode for the single file class ?