本文整理汇总了Java中java.lang.instrument.Instrumentation.appendToBootstrapClassLoaderSearch方法的典型用法代码示例。如果您正苦于以下问题:Java Instrumentation.appendToBootstrapClassLoaderSearch方法的具体用法?Java Instrumentation.appendToBootstrapClassLoaderSearch怎么用?Java Instrumentation.appendToBootstrapClassLoaderSearch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.instrument.Instrumentation
的用法示例。
在下文中一共展示了Instrumentation.appendToBootstrapClassLoaderSearch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static void main(String args[]) throws IOException {
JarFile bootclasses = new JarFile("BootSupport.jar");
JarFile agentclasses = new JarFile("AgentSupport.jar");
Instrumentation ins = Agent.getInstrumentation();
// Test 1: Add BootSupport.jar to boot class path and check that
// BootSupport is loaded by the bootstrap class loader
ins.appendToBootstrapClassLoaderSearch(bootclasses);
checkLoadedByLoader("BootSupport", null);
// Test 2: Add AgentSupport.jar to the system class path and check that
// AgentSupport is loaded by the system class loader.
try {
ins.appendToSystemClassLoaderSearch(agentclasses);
checkLoadedByLoader("AgentSupport", ClassLoader.getSystemClassLoader());
} catch (UnsupportedOperationException x) {
System.out.println("System class loader does not support adding to class path");
}
// throw exception if a test failed
if (failures > 0) {
throw new RuntimeException(failures + " test(s) failed.");
}
}
示例2: main0
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
private static void main0(String agentArgs, Instrumentation instrumentation,
BiConsumer<String, Instrumentation> delegate) {
if (ClassLoader.getSystemResource(BTM_SCRIPTS_RESOURCE_PATH) == null) {
System.err.println("Could not load " + BTM_SCRIPTS_RESOURCE_PATH + "."
+ "Agent will not be started.");
return;
}
try {
ConfigService.initialize();
} catch (ConfigurationException | IOException | RuntimeException e) {
System.err.println(e.getMessage());
System.err.println("Agent will not be started.");
return;
}
if (agentArgs != null && agentArgs.trim().length() > 0) {
agentArgs += "," + AGENT_PARAMS;
} else {
agentArgs = AGENT_PARAMS;
}
JarFile bytemanJar = createBytemanJar();
if (bytemanJar == null) {
System.err.println("Could not locate: " + BYTEMAN_JAR_RESOURCE_NAME);
System.err.println("Agent will not be started.");
return;
}
instrumentation.appendToBootstrapClassLoaderSearch(bytemanJar);
delegate.accept(agentArgs, instrumentation);
}
示例3: premain
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static void premain(String agentArgs, Instrumentation inst) {
String jarPath = "D:/creditRepository/ce-datamonitorsystem/com.creditease.uav.ttl/target/com.creditease.uav.ttl-2.1.0-agent.jar";
inst.addTransformer(new TtlTransformer());
try {
inst.appendToBootstrapClassLoaderSearch(new JarFile(jarPath));
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例4: installUAVjdk
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
private static void installUAVjdk(Instrumentation inst, String extJdkLib) {
URL[] jdkJars = JarUtil.loadJars(extJdkLib);
try {
for (URL temp : jdkJars) {
inst.appendToBootstrapClassLoaderSearch(new JarFile(temp.getFile()));
}
}
catch (IOException e) {
// ignore
e.printStackTrace();
}
}
示例5: main
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
private static synchronized InetSocketAddress main(final Map<String, String> featureMap,
final Instrumentation inst) {
final String namespace = getNamespace(featureMap);
final String propertiesFilePath = getPropertiesFilePath(featureMap);
final String coreFeatureString = toFeatureString(featureMap);
try {
// 将Spy注入到BootstrapClassLoader
inst.appendToBootstrapClassLoaderSearch(new JarFile(new File(SANDBOX_SPY_JAR_PATH)));
// 构造自定义的类加载器,尽量减少Sandbox对现有工程的侵蚀
final ClassLoader agentLoader = loadOrDefineClassLoader(namespace, SANDBOX_CORE_JAR_PATH);
// CoreConfigure类定义
final Class<?> classOfConfigure = agentLoader.loadClass(CLASS_OF_CORE_CONFIGURE);
// 反序列化成CoreConfigure类实例
final Object objectOfCoreConfigure = classOfConfigure.getMethod("toConfigure", String.class, String.class)
.invoke(null, coreFeatureString, propertiesFilePath);
// JtServer类定义
final Class<?> classOfJtServer = agentLoader.loadClass(CLASS_OF_JETTY_CORE_SERVER);
// 获取JtServer单例
final Object objectOfJtServer = classOfJtServer
.getMethod("getInstance")
.invoke(null);
// gaServer.isBind()
final boolean isBind = (Boolean) classOfJtServer.getMethod("isBind").invoke(objectOfJtServer);
// 如果未绑定,则需要绑定一个地址
if (!isBind) {
try {
classOfJtServer
.getMethod("bind", classOfConfigure, Instrumentation.class)
.invoke(objectOfJtServer, objectOfCoreConfigure, inst);
} catch (Throwable t) {
classOfJtServer.getMethod("destroy").invoke(objectOfJtServer);
throw t;
}
}
// 返回服务器绑定的地址
return (InetSocketAddress) classOfJtServer
.getMethod("getLocal")
.invoke(objectOfJtServer);
} catch (Throwable cause) {
throw new RuntimeException("sandbox attach failed.", cause);
}
}
示例6: addJarToBootstrap
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
/**
* 添加jar文件到jdk的跟路径下,优先加载
*
* @param inst {@link Instrumentation}
*/
public static void addJarToBootstrap(Instrumentation inst) throws IOException {
String localJarPath = getLocalJarPath();
inst.appendToBootstrapClassLoaderSearch(new JarFile(localJarPath));
}