Package org.glassfish.embeddable.archive
Class ScatteredArchive
java.lang.Object
org.glassfish.embeddable.archive.ScatteredArchive
Abstraction for a Scattered Jakarta 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, bhavanishankar@java.net
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration values for the scattered Jakarta EE module types. -
Constructor Summary
ConstructorsConstructorDescriptionScatteredArchive(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
Modifier and TypeMethodDescriptionvoidaddClassPath(File classpath) Add a directory or a JAR file to this scattered archive.voidaddCurrentClassPath(String... excludePatterns) Add all directories and JAR files on the current classpath to this scattered archive usingIgnores Jakarta EE API and GlassFish Embedded JAR files (those that match theinvalid @link
{@link #addClassPath(java.io.File).jakarta.andglassfish-embedded-prefixes).voidaddCurrentClassPath(Predicate<String> exclude) Add all directories and JAR files on the current classpath to this scattered archive usingIgnores Jakarta EE API and GlassFish Embedded JAR files (those that match theinvalid @link
{@link #addClassPath(java.io.File).jakarta.andglassfish-embedded-prefixes).voidaddMetadata(File metadata) Add a new metadata to this scattered archive.voidaddMetadata(File metadata, String name) Add a new metadata to this scattered archive.toURI()Get the deployable URI for this scattered archive.
-
Constructor Details
-
ScatteredArchive
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.jsSome 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 Details
-
addClassPath
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.pngthen 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.
-
addCurrentClassPath
Add all directories and JAR files on the current classpath to this scattered archive usingIgnores Jakarta EE API and GlassFish Embedded JAR files (those that match theinvalid @link
{@link #addClassPath(java.io.File).jakarta.andglassfish-embedded-prefixes). Reads the current classpath from thejava.class.pathsystem property. If it's not available, nothing is added to the classpath. The classpath that is added is considered as a plain Java CLASSPATH. If a classpath element is not found, a warning is logged usingSystem.Loggerand the element is ignored.- Parameters:
excludePatterns- If a JAR file name matches any of these regular expressions- See Also:
-
addCurrentClassPath
Add all directories and JAR files on the current classpath to this scattered archive usingIgnores Jakarta EE API and GlassFish Embedded JAR files (those that match theinvalid @link
{@link #addClassPath(java.io.File).jakarta.andglassfish-embedded-prefixes). Reads the current classpath from thejava.class.pathsystem property. If it's not available, nothing is added to the classpath. The classpath that is added is considered as a plain Java CLASSPATH. If a classpath element is not found, a warning is logged usingSystem.Loggerand the element is ignored.- Parameters:
exclude- A predicate to exclude mathing elements from the classpath. If this predicate returnstruefor the whole path to the classpath element, the element is not added to the classpath- See Also:
-
addMetadata
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
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
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.
-