http://classworlds.codehaus.org/apiusage.html

本文介绍了如何使用Java API创建新的ClassWorlds实例,并通过添加构成部分和建立不同ClassRealm之间的链接来加载和使用特定的类。

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.

转载于:https://www.cnblogs.com/heidsoft/p/4179249.html

C:\Users\c>mvn install:install-file -Dfile=spring-test-5.1.8.RELEASE.jar -DgroupId=org.springframework -DartifactId=spring-test -Dversion=5.1.8.RELEASE -Dpackaging=jar [INFO] Scanning for projects... Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 9.2 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom (13 KB at 132.6 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-parent/21/maven-parent-21.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-parent/21/maven-parent-21.pom (26 KB at 79.2 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/apache/10/apache-10.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/apache/10/apache-10.pom (15 KB at 73.0 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar (25 KB at 71.4 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom (7 KB at 20.9 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-plugins/23/maven-plugins-23.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-plugins/23/maven-plugins-23.pom (9 KB at 109.5 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-parent/22/maven-parent-22.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-parent/22/maven-parent-22.pom (30 KB at 330.1 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/apache/11/apache-11.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/apache/11/apache-11.pom (15 KB at 45.6 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.jar (27 KB at 333.2 KB/sec) [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom --- Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-plugin-api/2.0.6/maven-plugin-api-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-plugin-api/2.0.6/maven-plugin-api-2.0.6.pom (2 KB at 3.7 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven/2.0.6/maven-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven/2.0.6/maven-2.0.6.pom (9 KB at 71.8 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-parent/5/maven-parent-5.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-parent/5/maven-parent-5.pom (15 KB at 236.2 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/apache/3/apache-3.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/apache/3/apache-3.pom (4 KB at 38.5 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-project/2.0.6/maven-project-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-project/2.0.6/maven-project-2.0.6.pom (3 KB at 37.3 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-settings/2.0.6/maven-settings-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-settings/2.0.6/maven-settings-2.0.6.pom (2 KB at 26.1 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-model/2.0.6/maven-model-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-model/2.0.6/maven-model-2.0.6.pom (3 KB at 49.6 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-utils/1.4.1/plexus-utils-1.4.1.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-utils/1.4.1/plexus-utils-1.4.1.pom (2 KB at 21.9 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus/1.0.11/plexus-1.0.11.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus/1.0.11/plexus-1.0.11.pom (9 KB at 116.8 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-container-default/1.0-alpha-9-stable-1/plexus-container-default-1.0-alpha-9-stable-1.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-container-default/1.0-alpha-9-stable-1/plexus-container-default-1.0-alpha-9-stable-1.pom (4 KB at 46.5 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-containers/1.0.3/plexus-containers-1.0.3.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-containers/1.0.3/plexus-containers-1.0.3.pom (492 B at 7.6 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus/1.0.4/plexus-1.0.4.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus/1.0.4/plexus-1.0.4.pom (6 KB at 96.6 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/junit/junit/3.8.1/junit-3.8.1.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/junit/junit/3.8.1/junit-3.8.1.pom (998 B at 14.3 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.pom (7 KB at 58.7 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.pom (4 KB at 51.8 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-profile/2.0.6/maven-profile-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-profile/2.0.6/maven-profile-2.0.6.pom (2 KB at 23.6 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-artifact-manager/2.0.6/maven-artifact-manager-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-artifact-manager/2.0.6/maven-artifact-manager-2.0.6.pom (3 KB at 40.6 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-repository-metadata/2.0.6/maven-repository-metadata-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-repository-metadata/2.0.6/maven-repository-metadata-2.0.6.pom (2 KB at 18.2 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-artifact/2.0.6/maven-artifact-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-artifact/2.0.6/maven-artifact-2.0.6.pom (2 KB at 22.3 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-plugin-registry/2.0.6/maven-plugin-registry-2.0.6.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-plugin-registry/2.0.6/maven-plugin-registry-2.0.6.pom (2 KB at 25.0 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom (3 KB at 30.3 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus/3.1/plexus-3.1.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus/3.1/plexus-3.1.pom (19 KB at 256.0 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/sonatype/spice/spice-parent/17/spice-parent-17.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/sonatype/spice/spice-parent/17/spice-parent-17.pom (7 KB at 91.7 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/sonatype/forge/forge-parent/10/forge-parent-10.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/sonatype/forge/forge-parent/10/forge-parent-10.pom (14 KB at 181.4 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom (2 KB at 11.1 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom (5 KB at 57.2 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom (8 KB at 87.2 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom (8 KB at 72.4 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-plugin-api/2.0.6/maven-plugin-api-2.0.6.jar Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-project/2.0.6/maven-project-2.0.6.jar Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-profile/2.0.6/maven-profile-2.0.6.jar Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-settings/2.0.6/maven-settings-2.0.6.jar Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-plugin-registry/2.0.6/maven-plugin-registry-2.0.6.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-plugin-api/2.0.6/maven-plugin-api-2.0.6.jar (13 KB at 115.2 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-container-default/1.0-alpha-9-stable-1/plexus-container-default-1.0-alpha-9-stable-1.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-settings/2.0.6/maven-settings-2.0.6.jar (48 KB at 409.8 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/junit/junit/3.8.1/junit-3.8.1.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-plugin-registry/2.0.6/maven-plugin-registry-2.0.6.jar (29 KB at 241.4 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-profile/2.0.6/maven-profile-2.0.6.jar (35 KB at 294.1 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-model/2.0.6/maven-model-2.0.6.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-project/2.0.6/maven-project-2.0.6.jar (114 KB at 766.6 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-artifact-manager/2.0.6/maven-artifact-manager-2.0.6.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar (37 KB at 144.2 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-repository-metadata/2.0.6/maven-repository-metadata-2.0.6.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-model/2.0.6/maven-model-2.0.6.jar (85 KB at 320.8 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-artifact/2.0.6/maven-artifact-2.0.6.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/junit/junit/3.8.1/junit-3.8.1.jar (119 KB at 434.7 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-container-default/1.0-alpha-9-stable-1/plexus-container-default-1.0-alpha-9-stable-1.jar (190 KB at 660.7 KB/sec) Downloading: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-artifact-manager/2.0.6/maven-artifact-manager-2.0.6.jar (56 KB at 184.6 KB/sec) Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-repository-metadata/2.0.6/maven-repository-metadata-2.0.6.jar (24 KB at 72.6 KB/sec) Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-artifact/2.0.6/maven-artifact-2.0.6.jar (86 KB at 248.0 KB/sec) Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar (226 KB at 601.7 KB/sec) Downloaded: http://maven.aliyun.com/nexus/content/repositories/central/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar (12 KB at 30.2 KB/sec) [ERROR] The specified file 'C:\Users\c\spring-test-5.1.8.RELEASE.jar' not exists [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.888 s [INFO] Finished at: 2025-07-29T10:57:44+08:00 [INFO] Final Memory: 10M/201M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install-file (default-cli) on project standalone-pom: The specified file 'C:\Users\c\spring-test-5.1.8.RELEASE.jar' not exists -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值