Skip to content

Instantly share code, notes, and snippets.

@TsuyoshiUshio
Created May 26, 2020 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TsuyoshiUshio/6d8d41addb4afd22fdebd8333aef8323 to your computer and use it in GitHub Desktop.
Save TsuyoshiUshio/6d8d41addb4afd22fdebd8333aef8323 to your computer and use it in GitHub Desktop.
GraalVM sample
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
public class Main {
public static void main(String args[]){
try{
String pathToJar = args[0];
System.out.println(pathToJar);
URL[] urls = { new URL("jar:file:" + pathToJar+"!/")};
URLClassLoader cl = URLClassLoader.newInstance(urls);
Class<?> lib = cl.loadClass("com.simplearchitect.lib.LibrarySample");
Object sample = lib.getDeclaredConstructor().newInstance();
System.out.println(lib.getName());
Method execute =lib.getMethod("execute");
execute.invoke(sample);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment