Search in sources :

Example 1 with OpenURLClassLoader

use of fish.payara.micro.boot.loader.OpenURLClassLoader in project Payara by payara.

the class PayaraMicroImpl method addLibrary.

@Override
public PayaraMicroImpl addLibrary(File lib) {
    OpenURLClassLoader loader = (OpenURLClassLoader) this.getClass().getClassLoader();
    if (lib.exists() && lib.canRead() && lib.getName().endsWith(".jar")) {
        try {
            loader.addURL(lib.toURI().toURL());
            LOGGER.log(Level.INFO, "Added " + lib.getAbsolutePath() + " to classpath");
        } catch (MalformedURLException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    } else {
        LOGGER.log(Level.SEVERE, "Unable to read jar " + lib.getName());
    }
    return this;
}
Also used : MalformedURLException(java.net.MalformedURLException) OpenURLClassLoader(fish.payara.micro.boot.loader.OpenURLClassLoader)

Example 2 with OpenURLClassLoader

use of fish.payara.micro.boot.loader.OpenURLClassLoader in project Payara by payara.

the class MicroGlassFishRuntime method newGlassFish.

@Override
public GlassFish newGlassFish(GlassFishProperties glassfishProperties) throws GlassFishException {
    System.setProperty("com.sun.aas.installRoot", System.getProperty("com.sun.aas.instanceRoot"));
    System.setProperty("com.sun.aas.installRootURI", System.getProperty("com.sun.aas.instanceRootURI"));
    glassfishProperties.setProperty("com.sun.aas.installRoot", System.getProperty("com.sun.aas.instanceRoot"));
    glassfishProperties.setProperty("com.sun.aas.installRootURI", System.getProperty("com.sun.aas.instanceRootURI"));
    StartupContext context = new StartupContext(glassfishProperties.getProperties());
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    if (tccl instanceof OpenURLClassLoader) {
        // Only our runtime classloaders list individual runtime jars.
        SingleHK2Factory.initialize(tccl);
    } else {
        // Otherwise we assume we're in rootdir classloader and runtime jars are listed in boot jar's Class-Path
        // manifest attribute
        initializeWithJarManifest(tccl);
    }
    ModulesRegistry registry = AbstractFactory.getInstance().createModulesRegistry();
    ServiceLocator habitat = registry.newServiceLocator();
    DynamicConfigurationService dcs = habitat.getService(DynamicConfigurationService.class);
    DynamicConfiguration config = dcs.createDynamicConfiguration();
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(context));
    config.commit();
    registry.populateServiceLocator("default", habitat, Arrays.asList(new PayaraMicroInhabitantsParser(), new EmbeddedInhabitantsParser(), new DuplicatePostProcessor()));
    registry.populateConfig(habitat);
    ModuleStartup kernel = habitat.getService(ModuleStartup.class);
    gf = new MicroGlassFish(kernel, habitat, glassfishProperties.getProperties());
    return gf;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) OpenURLClassLoader(fish.payara.micro.boot.loader.OpenURLClassLoader) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) DuplicatePostProcessor(org.glassfish.hk2.utilities.DuplicatePostProcessor) OpenURLClassLoader(fish.payara.micro.boot.loader.OpenURLClassLoader) EmbeddedInhabitantsParser(com.sun.enterprise.glassfish.bootstrap.EmbeddedInhabitantsParser) ModuleStartup(com.sun.enterprise.module.bootstrap.ModuleStartup)

Aggregations

OpenURLClassLoader (fish.payara.micro.boot.loader.OpenURLClassLoader)2 EmbeddedInhabitantsParser (com.sun.enterprise.glassfish.bootstrap.EmbeddedInhabitantsParser)1 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1 ModuleStartup (com.sun.enterprise.module.bootstrap.ModuleStartup)1 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)1 MalformedURLException (java.net.MalformedURLException)1 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)1 DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)1 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)1 DuplicatePostProcessor (org.glassfish.hk2.utilities.DuplicatePostProcessor)1