public class ScatteredArchive extends Object
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(); glassfish.start(); // Create a scattered web application. ScatteredArchive archive = new ScatteredArchive("testapp", ScatteredArchive.Type.WAR); // target/classes directory contains my complied servlets archive.addClassPath(new File("target", "classes")); // resources/sun-web.xml is my WEB-INF/sun-web.xml archive.addMetadata(new File("resources", "sun-web.xml")); // resources/MyLogFactory is my META-INF/services/org.apache.commons.logging.LogFactory archive.addMetadata(new File("resources", "MyLogFactory"), "META-INF/services/org.apache.commons.logging.LogFactory"); Deployer deployer = glassfish.getDeployer(); // Deploy my scattered web application deployer.deploy(archive.toURI());
| Modifier and Type | Class and Description |
|---|---|
static class |
ScatteredArchive.Type
Enumeration values for the scattered Java EE module types.
|
| Constructor and Description |
|---|
ScatteredArchive(String name,
ScatteredArchive.Type type)
Construct a new empty scattered archive.
|
ScatteredArchive(String name,
ScatteredArchive.Type type,
File rootDirectory)
Construct a new scattered archive with all the contents from the rootDirectory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addClassPath(File classpath)
Add a directory or a JAR file to this scattered archive.
|
void |
addMetadata(File metadata)
Add a new metadata to this scattered archive.
|
void |
addMetadata(File metadata,
String name)
Add a new metadata to this scattered archive.
|
URI |
toURI()
Get the deployable URI for this scattered archive.
|
public ScatteredArchive(String name, ScatteredArchive.Type type)
name - name of the archive.type - type of the archiveNullPointerException - if name or type is nullpublic ScatteredArchive(String name, ScatteredArchive.Type type, File rootDirectory) throws IOException
rootDirectory/WEB-INF/classes/org/myorg/FooServlet.class
rootDirectory/WEB-INF/classes/org/myorg/Bar.class
rootDirectory/WEB-INF/web.xml
rootDirectory/WEB-INF/lib/myjar.jar
rootDirectory/index.jsp
rootDirectory/theme.css
rootDirectory/helper.js
Some files can then be scattered in different locations and be specified
through the appropriate add methods of this class.
name - name of the archive.type - type of the archiverootDirectory - root directory.NullPointerException - if name, type or rootDirectory is null.IOException - if rootDirectory does not exist.IllegalArgumentException - if rootDirectory is not a directory.public void addClassPath(File classpath) throws IOException
TEMP/abc/org/myorg/a/A.class
TEMP/abc/org/myorg/b/B.class
TEMP/abc/com/xyz/c/C.class
TEMP/abc/LocalStrings.properties
TEMP/abc/image/1.png
then addClassPath(new File("TEMP", "abc") will make:
(a) The following classes available in the deployed scattered archive application:
org.myorg.a.A
org.myorg.b.B
com.xyz.c.C
(b) LocalStrings.properties available in the deployed scattered archive application.
So, the deployed application can do ResourceBundle.getBundle("LocalStrings");
(c) image/1.png available in the deployed scattered archive application.
So, the deployed application can load the image file via getClass().getClassLoader().getResource("image/1.png");
If there is any other type of file under TEMP/abc then it will also be available
in the deployed scattered archive application's classloader.
Case 2: classpath is a JAR file
Let us say there is TEMP/xyz.jar, then addClassPath(new File("TEMP", "xyz.jar"))
will make all the classes and any random files inside TEMP/xyz.jar
available in the deployed scattered archive application.classpath - A directory or a JAR file.NullPointerException - if classpath is nullIOException - if the classpath is not found.public void addMetadata(File metadata) throws IOException
addMetadata(metadata, null)
Follows the same semantics as addMetadata(File, String) method.IOExceptionpublic void addMetadata(File metadata, String name) throws IOException
"WEB-INF/" + metadata.getName() for WAR type archive.
"META-INF/" + metadata.getName() for other type of archive.
If the scattered archive already contains the metadata with the same name,
then the old value is replaced.metadata - location of the metadataname - name of the metadata (e.g.,
META-INF/ejb.xml or META-INF/sun-ejb-jar.xml)NullPointerException - if metadata is nullIOException - if metadata does not exist.IllegalArgumentException - if metadata is a directory.public URI toURI() throws IOException
IOException - if any I/O error happens while building the URI
or while reading metadata, classpath elements, rootDirectory.Copyright © 2017–2020 Eclipse Foundation. All rights reserved.