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. Eclipse中使用Maven,报错“$MAVEN_HOME”

    1.今天在用eclipse时,执行maven命令,报错,如图"$MAVEN_HOME" 解决方案: 1.点击 windows---preferences,打开preferences ...

  2. Winform开发常用控件之TreeView菜单导航和权限用法

    TreeView一个很棒的控件,我们在做WEB开发时常常犯困的一个东东.当然这里介绍winform里面的用法唠. 先介绍几个属性吧,CheckBoxes设置为true的话树形节点前面会出现checkb ...

  3. PyalgoTrade 交易(五)

    我们继续采取简单的策略,这次模拟实际交易.这个想法很简单: 如果调整后的收盘价高于SMA(15),我们将进入多头仓位(我们下单买入市价). 如果调整后的收盘价低于SMA(15),我们退出多头头寸(我们 ...

  4. C# 图片生成缩略图

    C# 图片生成缩略图方法: /// <summary> /// 生成缩略图 /// </summary> /// <param name="fileName&q ...

  5. 458 - The Decoder & C语言gets函数,字符输出输出 & toascii()

    Write a complete program that will correctly decode a set of characters into a valid message. Your p ...

  6. free命令学习 输出理解

    命令 [root@localhost ~]# free -m total used free shared buffers cached Mem: 7869 7651 218 1 191 5081 - ...

  7. ambassador 学习九 多ambassador部署说明

    目前官方稳文档没有写,但是demo 里面有,所以就整理出来,其实目前demo里面的 多实例部署用了多个服务的service(使用nodeport 暴露地址,具体使用就是制定ambassador 实例的 ...

  8. springboot 整合 elasticsearch

    1引入jar包 <!--elasticsearch--> <dependency> <groupId>org.springframework.boot</gr ...

  9. js 获取下一秒 时间

    function getNextTime(start){ //var start = '09:30:00'; var _s = new Date(); var startDate = _s.getFu ...

  10. 【POJ】1935 Journey(树形dp)

    题目 传送门:QWQ 分析 凉凉. 答案是所有要经过的点到根所经过的边权和减去最大的边权. 代码 vector好慢啊 #include <cstdio> #include <vect ...