API Usage

The Java API can be used to create new realms and connect realms together through importation of specific packages.

The core of the classworlds infrastructure is the ClassWorld class. An application must create a ClassWorld instance. It is advisable to store the instance as a singleton or some other handy location.

ClassWorld world = new ClassWorld();

Once a ClassWorld is created, realms within it can be created. These realms effectively only allow loading of the core JVM classes.

ClassWorld world = new ClassWorld();

ClassRealm containerRealm    = world.newRealm( "container" );
ClassRealm logComponentRealm = world.newRealm( "logComponent" );

In order to make each ClassRealm useful, constituent must be added to that each can provide certain classes.

containerRealm.addConstituent( containerJarUrl );
logComponentRealm.addConstituent( logComponentJarUrl );

Now, links between the various realms need to be created to allow classes loaded from one to be available to classes loaded in another.

logComponentRealm.importFrom( "container",
"com.werken.projectz.component" );

The container implementation can then be loaded from it's realm and used.

Class containerClass = containerRealm.loadClass( CONTAINER_CLASSNAME );

MyContainer container = (MyContainer) containerClass.newInstance();

Thread.currentThread().setContextClassLoader( containerRealm.getClassLoader() );

container.run();

Ideally, the container itself would be responsible for creating a ClassRealm for each component that's loaded, and importing the component contract interfaces into the component's ClassRealm and using loadClass(..) to gain entry into the sandboxed component realm.

http://classworlds.codehaus.org/apiusage.html的更多相关文章

  1. (五)Maven目录结构及常用命令说明

    前面提到的部分知识有涉及到Maven目录结构与Maven常用的一些命令,在这里专门给大家做个简单的介绍. 1.Maven目录结构说明 Maven总体目录结构如下图: bin目录:该目录包含了mvn运行 ...

  2. maven 简介

    本书代码下载 大家可以从我的网站下载本书的代码:http://www.juvenxu.com/mvn-in-action/,也可以通过我的网站与我取得联系,欢迎大家与我交流任何关于本书的问题和关于Ma ...

  3. Maven的安装、配置及使用入门

    Maven的安装.配置及使用入门 本书代码下载 大家可以从我的网站下载本书的代码:http://www.juvenxu.com/mvn-in-action/,也可以通过我的网站与我取得联系,欢迎大家与 ...

  4. 1.Maven的安装及配置

    1 Maven 介绍 Maven这个词可以翻译为“知识的积累”,也可以翻译为“专家”或“内行”.本书将介绍Maven这一跨平台的项目管理工具.作为Apache组织中的一个颇为成功的开源项目,Maven ...

  5. 笔记:Maven 下载和安装

    Windows 安装 下载 Apache Maven,下载地址为 http://maven.apache.org/ 解压缩下载的 ZIP 文件,复制到安装目录 增加环境变量 M2_HOME ,值为 A ...

  6. (一)maven之——maven基础及本地仓库的配置

    一.初步了解maven Apache Maven是一个软件项目管理的综合工具.基于项目对象模型(POM)的概念,提供了帮助管理构建.文档.报告.依赖.发布等方法,Maven简化和标准化项目建设过程.处 ...

  7. 转载maven安装,配置,入门

    转载:http://www.cnblogs.com/dcba1112/archive/2011/05/01/2033805.html 本书代码下载 大家可以从我的网站下载本书的代码:http://ww ...

  8. Maven系列(二)之安装和配置详解

    检查JDK环境 在安装Maven之前,首先要确认你已经正确安装了JDK.Maven可以运行在JDK 1.4及以上的版本上. 打开cmd输入: java -version 下载Maven Maven官网 ...

  9. Maven 教程(5)— Maven目录结构及常用命令说明

    原文地址:https://blog.csdn.net/liupeifeng3514/article/details/79543159 1.Maven目录结构说明 Maven总体目录结构如下图: bin ...

随机推荐

  1. 第1课 学习C++的意义

    C++是C语言的加强,它们之间并不是对立的关系. 学习C++的优势: 现代软件产品的架构图: 操作系统抽象层:可有可无,但是作为一个移植性好的软件一定需要这一层.这一层的作用就是把操作系统提供的接口做 ...

  2. LTE-Advanced(4G)主要技术学习:CA、CoMp、HetNet

    CA:Carrier Aggregation,载波聚合 从LTE到LTE-Advanced演进过程中,更宽频谱的需求是影响演进的最重要因素,为此3GPP标准提出了载波聚合技术.简单地说,它可以将多个载 ...

  3. 使用TortoiseGit+码云管理项目代码

    1.下载安装msysgit. 2.下载安装tortoisegit. 3.创建ssh密钥. 开始–所有程序–TortoiseGit–PuTTYgen 生成方法:点击“Generate”后,鼠标在key下 ...

  4. python的继承顺序

    python的继承顺序 python 创建类时分为新式类和旧式类 class A: # 经典类 def __init__(self): pass # 新类,可以在这里加 __metaclass__ = ...

  5. gcc编译器配置

    一.使用交叉编译器编译 1.安装交叉编译工具链 2.导出环境变量 [ubuntu @tmp]$ export PATH=$PATH:/usr/local/oecore-x86_64/sysroots/ ...

  6. Android UiAutomator环境搭建及使用(QQ交流群:490451176)

    Android自动化框架常用的有很多,本身也提供了很多自动化测试框架,每个都有其优势和不足 .当然对于我们做UI自动化测试来说,简单易用即可. UiAutomator也是Android提供的自动化测试 ...

  7. 虚拟化环境下的CentOS7网络环境存在的问题

    http://dgd2010.blog.51cto.com/1539422/1592821/ 为什么要进行一次测试? 在使用CentOS7的过程中发现网络部分有很多与CentOS6所不同的地方. 1. ...

  8. springmvc 使用Jackson的配置

    <!--start:使用Jackson 1.x的配置,需要导入的jar包:jackson-core-lpgl-xxx.jar.jackson-mapper-lgpl-xxx.jar --> ...

  9. RK3288 device descriptor read/64, error -32

    CPU:RK3288 系统:Android 5.1 主板有两个USB接口,一个接USB摄像头,一个接身份证模块. 插入摄像头可以正常打开,再插入身份证模块时,摄像头就会卡主,而且身份证模块无法识别,内 ...

  10. Oracle 表空间查询与操作方法

    一.查询篇 1.查询oracle表空间的使用情况 select b.file_id 文件ID,  b.tablespace_name 表空间,  b.file_name 物理文件名,  b.bytes ...