Package org.glassfish.embeddable.archive
Class ScatteredArchive
- java.lang.Object
-
- org.glassfish.embeddable.archive.ScatteredArchive
-
public class ScatteredArchive extends Object
Abstraction for a Scattered Java EE module (parts disseminated in various directories). Usage example :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());
- Author:
- Jerome Dochez, [email protected]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ScatteredArchive.Type
Enumeration values for the scattered Java EE module types.
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
ScatteredArchive
public ScatteredArchive(String name, ScatteredArchive.Type type)
Construct a new empty scattered archive.- Parameters:
name
- name of the archive.type
- type of the archive- Throws:
NullPointerException
- if name or type is null
-
ScatteredArchive
public ScatteredArchive(String name, ScatteredArchive.Type type, File rootDirectory) throws IOException
Construct a new scattered archive with all the contents from the rootDirectory. By default, a scattered archive is not different from any other archive where all the files are located under a top level directory (rootDirectory). For example, In case of a WAR type archive, the rootDirectory should look like this: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.- Parameters:
name
- name of the archive.type
- type of the archiverootDirectory
- root directory.- Throws:
NullPointerException
- if name, type or rootDirectory is null.IOException
- if rootDirectory does not exist.IllegalArgumentException
- if rootDirectory is not a directory.
-
-
Method Detail
-
addClassPath
public void addClassPath(File classpath) throws IOException
Add a directory or a JAR file to this scattered archive. The classpath that is added is considered as a plain Java CLASSPATH. Case 1 : classpath is a directory: Let us say there is TEMP/abc directory, which has following contents: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.- Parameters:
classpath
- A directory or a JAR file.- Throws:
NullPointerException
- if classpath is nullIOException
- if the classpath is not found.
-
addMetadata
public void addMetadata(File metadata) throws IOException
Add a new metadata to this scattered archive. The addMetadata(metadata) method has the same effect as:addMetadata(metadata, null)
Follows the same semantics asaddMetadata(File, String)
method.- Throws:
IOException
-
addMetadata
public void addMetadata(File metadata, String name) throws IOException
Add a new metadata to this scattered archive. A metadata is identified by its name (e.g., META-INF/ejb.xml). If the specified name is null, then the metadata is considered as a deployment descriptor metadata and the name is computed as:"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.- Parameters:
metadata
- location of the metadataname
- name of the metadata (e.g., META-INF/ejb.xml or META-INF/sun-ejb-jar.xml)- Throws:
NullPointerException
- if metadata is nullIOException
- if metadata does not exist.IllegalArgumentException
- if metadata is a directory.
-
toURI
public URI toURI() throws IOException
Get the deployable URI for this scattered archive. Note : java.io.tmpdir is used while building the URI.- Returns:
- Deployable scattered archive URI.
- Throws:
IOException
- if any I/O error happens while building the URI or while reading metadata, classpath elements, rootDirectory.
-
-