-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathapiusage.html
211 lines (174 loc) · 7.68 KB
/
apiusage.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 2.0.0 from src/site/xdoc/apiusage.xml at 2025-04-05
| Rendered using Apache Maven Fluido Skin 2.0.1
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 2.0.0" />
<meta name="author" content="bob mcwhirter" />
<title>Classworlds API Usage – Plexus Classworlds</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-2.0.1.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script src="./js/apache-maven-fluido-2.0.1.min.js"></script>
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['disableCookies']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.apache.org/";
_paq.push(['setTrackerUrl', u+'/matomo.php']);
_paq.push(['setSiteId', '18']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'/matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body>
<div class="container-fluid container-fluid-top">
<header>
<div id="banner">
<div class="pull-left"><div id="bannerLeft"><h1>Plexus Classworlds</h1></div></div>
<div class="pull-right"></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li><a href="../">Plexus</a><span class="divider">/</span></li>
<li><a href="./">Plexus Classworlds</a><span class="divider">/</span></li>
<li class="active">Classworlds API Usage <a href="https://github.com/codehaus-plexus/plexus-classworlds/tree/plexus-classworlds-2.9.0/src/site/xdoc/apiusage.xml"><img src="./images/accessories-text-editor.png" alt="Edit" /></a></li>
<li id="publishDate" class="pull-right"><span class="divider">|</span> Last Published: 2025-04-05</li>
<li id="projectVersion" class="pull-right">Version: 2.9.0</li>
</ul>
</div>
</header>
<div class="row-fluid">
<header id="leftColumn" class="span2">
<nav class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Overview</li>
<li><a href="index.html">Introduction</a></li>
<li><a href="launcher.html">Launcher</a></li>
<li class="active"><a>API Usage</a></li>
<li><a href="apidocs/index.html">JavaDocs</a></li>
<li><a href="xref/index.html">Source Xref</a></li>
<li class="nav-header">Project Documentation</li>
<li><a href="project-info.html"><span class="icon-chevron-right"></span>Project Information</a></li>
<li><a href="project-reports.html"><span class="icon-chevron-right"></span>Project Reports</a></li>
<li class="nav-header">Plexus Projects</li>
<li><a href="../plexus-archiver/">Plexus Archiver</a></li>
<li><a href="./">Plexus Classworlds</a></li>
<li><a href="../plexus-compiler/">Plexus Compiler</a></li>
<li><a href="../plexus-i18n/">Plexus i18n</a></li>
<li><a href="../plexus-interactivity/">Plexus Interactivity</a></li>
<li><a href="../plexus-interpolation/">Plexus Interpolation</a></li>
<li><a href="../plexus-io/">Plexus IO</a></li>
<li><a href="../plexus-languages/">Plexus Languages</a></li>
<li><a href="../modello/">Plexus Modello</a></li>
<li><a href="../plexus-pom/">Plexus Parent POM</a></li>
<li><a href="../plexus-resources/">Plexus Resources</a></li>
<li><a href="../plexus-utils/">Plexus Utils</a></li>
<li><a href="../plexus-velocity/">Plexus Velocity</a></li>
<li><a href="../plexus-xml/">Plexus XML</a></li>
</ul>
</nav>
<div class="well sidebar-nav">
<form id="search-form" action="https://www.google.com/search" method="get" >
<input value="https://codehaus-plexus.github.io/" name="sitesearch" type="hidden" />
<input class="search-query" name="q" id="query" type="text" placeholder="Search with Google..." />
</form>
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<a href="https://maven.apache.org/" class="builtBy" target="_blank"><img class="builtBy" alt="Built by Maven" src="./images/logos/maven-feather.png" /></a>
</div>
</div>
</header>
<main id="bodyColumn" class="span10">
<section><a id="Classworlds_API_Usage"></a>
<h1>Classworlds API Usage</h1>
<p>
The Java API can be used to create new realms and connect
realms together through importation of specific packages.
</p>
<p>
The core of the <b>Classworlds</b> infrastructure is
the
<a href="apidocs/index.html?org/codehaus/plexus/classworlds/ClassWorld.html">ClassWorld</a>
class. An application must create a <code>ClassWorld</code> instance.
It is advisable to store the instance as a singleton or some other
handy location.
</p>
<pre class="prettyprint linenums"><code>
ClassWorld world = new ClassWorld();
</code></pre>
<p>
Once a <code>ClassWorld</code> is created, realms within it
can be created. These realms effectively only allow loading
of the core JVM classes initially.
</p>
<pre class="prettyprint linenums"><code>
ClassWorld world = new ClassWorld();
ClassRealm containerRealm = world.newRealm( "container" );
ClassRealm logComponentRealm = world.newRealm( "logComponent" );
</code></pre>
<p>
In order to make each <code>ClassRealm</code> useful, constituents
in form of URLs must be added to it where each can provide certain classes.
The URL must return either a JAR or a directory on the default file system.
</p>
<pre class="prettyprint linenums"><code>
containerRealm.addURL( containerJarUrl );
logComponentRealm.addURL( logComponentJarUrl );
</code></pre>
<p>
<code>ClassRealm</code>s can optionally be filtered to further restrict which classes/resources
are exposed. The filter is provided as additional argument to <code>world.newRealm( "filteredcontainer", myPredicate );</code>
</p>
<p>
Now, links between the various realms need to be created to allow
classes loaded from one to be available to classes loaded in another.
</p>
<pre class="prettyprint linenums"><code>
logComponentRealm.importFrom( "container",
"com.werken.projectz.component" );
</code></pre>
<p>
The container implementation can then be loaded from its realm
and used.
</p>
<pre class="prettyprint linenums"><code>
Class containerClass = containerRealm.loadClass( CONTAINER_CLASSNAME );
MyContainer container = (MyContainer) containerClass.newInstance();
Thread.currentThread().setContextClassLoader( containerRealm.getClassLoader() );
container.run();
</code></pre>
<p>
Ideally, the container itself would be responsible for creating
a <code>ClassRealm</code> for each component that's loaded, and
importing the component contract interfaces into the component's
<code>ClassRealm</code> and using <code>loadClass(..)</code>
to gain entry into the sandboxed component realm.
</p>
</section>
</main>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>© 2002–2025
<a href="https://codehaus-plexus.github.io/">Codehaus Plexus</a>
</p>
</div>
</div>
</footer>
</body>
</html>