Skip to content

Instantly share code, notes, and snippets.

@stain
Last active August 29, 2015 14:02
Show Gist options
  • Save stain/aaf5bc710defc36f5d16 to your computer and use it in GitHub Desktop.
Save stain/aaf5bc710defc36f5d16 to your computer and use it in GitHub Desktop.
Loading new artifacts from inside a Taverna Beanshell
import net.sf.taverna.raven.repository.Artifact;
import net.sf.taverna.raven.repository.BasicArtifact;
import net.sf.taverna.raven.repository.impl.LocalArtifactClassLoader;
LocalArtifactClassLoader cl = (LocalArtifactClassLoader) getClass().getClassLoader();
Artifact a = new BasicArtifact("com.example", "fred", "0.1.0");
cl.getRepository().addArtifact(a);
cl.getRepository().update(); // force any download and resolution
// Now we can get his classloader
ClassLoader hisCl = cl.getRepository().getLoader(a, cl);
Object fred = hisCl.loadClass("com.example.Fred").newInstance();
// In Beanshell we don't need to do further introspection and can do:
fred.doStuff();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment