Package org.opennms.bootstrap
Class Bootstrap
- java.lang.Object
-
- org.opennms.bootstrap.Bootstrap
-
- Direct Known Subclasses:
InstallerBootstrap
public abstract class Bootstrap extends Object
Bootstrap application for starting OpenNMS.
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
BOOT_PROPERTIES_NAME
protected static String
LIBRARY_PROPERTIES_NAME
protected static String
OPENNMS_HOME_PROPERTY
protected static String
OPENNMS_PROPERTIES_D_NAME
protected static String
OPENNMS_PROPERTIES_NAME
protected static String
RRD_PROPERTIES_NAME
protected static Path
VERSION_PROPERTIES
-
Constructor Summary
Constructors Constructor Description Bootstrap()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static void
executeClass(String classToExec, String classToExecMethod, String[] classToExecArgs, boolean appendClasspath)
protected static void
executeClass(String classToExec, String classToExecMethod, String[] classToExecArgs, boolean appendClasspath, boolean recurse)
protected static File
findOpenNMSHome()
Find the OpenNMS home directory.static File
findOpenNMSHomeUsingJarPath()
Determine the OpenNMS home directory based on the location of the JAR file containing this code.protected static List<File>
getPropertiesFiles(File opennmsHome)
Retrieves the list of configuration files containing system properties to be set.protected static boolean
isValidOpenNMSHome(File opennmsHome)
Validates the OpenNMS home directory by checking for known mandatory files.static ClassLoader
loadClasses(File dir, boolean recursive)
Create a ClassLoader with the JARs found in dir.static void
loadClasses(File dir, boolean recursive, List<URL> urls)
Add JARs found in dir to the LinkedList urls.static ClassLoader
loadClasses(String dirStr, boolean recursive, boolean append)
Create a ClassLoader with the JARs found in dirStr.protected static void
loadSystemProperties(File opennmsHome)
Load default properties from the specified OpenNMS home into the system properties.static void
main(String[] args)
Bootloader main method.static ClassLoader
newClassLoader(List<URL> urls)
Create a ClassLoader with the list of URLs found in urls.
-
-
-
Field Detail
-
VERSION_PROPERTIES
protected static final Path VERSION_PROPERTIES
-
BOOT_PROPERTIES_NAME
protected static final String BOOT_PROPERTIES_NAME
- See Also:
- Constant Field Values
-
RRD_PROPERTIES_NAME
protected static final String RRD_PROPERTIES_NAME
- See Also:
- Constant Field Values
-
LIBRARY_PROPERTIES_NAME
protected static final String LIBRARY_PROPERTIES_NAME
- See Also:
- Constant Field Values
-
OPENNMS_PROPERTIES_NAME
protected static final String OPENNMS_PROPERTIES_NAME
- See Also:
- Constant Field Values
-
OPENNMS_PROPERTIES_D_NAME
protected static final String OPENNMS_PROPERTIES_D_NAME
- See Also:
- Constant Field Values
-
OPENNMS_HOME_PROPERTY
protected static final String OPENNMS_HOME_PROPERTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
loadClasses
public static ClassLoader loadClasses(String dirStr, boolean recursive, boolean append) throws MalformedURLException
Create a ClassLoader with the JARs found in dirStr.- Parameters:
dirStr
- List of directories to search for JARs, separated byFile.pathSeparator
.recursive
- Whether to recurse into subdirectories of the directories in dirStr.append
- Append the URLs of the current {@link java.lang.Thread#getContextClassLoader()) to this classloader.- Returns:
- a
ClassLoader
object. - Throws:
MalformedURLException
- if any.
-
loadClasses
public static ClassLoader loadClasses(File dir, boolean recursive) throws MalformedURLException
Create a ClassLoader with the JARs found in dir.- Parameters:
dir
- Directory to search for JARsrecursive
- Whether to recurse into subdirectories of dir- Returns:
- a
ClassLoader
object. - Throws:
MalformedURLException
- if any.
-
newClassLoader
public static ClassLoader newClassLoader(List<URL> urls)
Create a ClassLoader with the list of URLs found in urls.- Parameters:
urls
- List of URLs to add to the ClassLoader's search list.- Returns:
- a
ClassLoader
object.
-
loadClasses
public static void loadClasses(File dir, boolean recursive, List<URL> urls) throws MalformedURLException
Add JARs found in dir to the LinkedList urls.- Parameters:
dir
- Directory to search for JARsrecursive
- Whether to recurse into subdirectories of the directory in dirurls
- LinkedList to append found JARs onto- Throws:
MalformedURLException
- if any.
-
getPropertiesFiles
protected static List<File> getPropertiesFiles(File opennmsHome)
Retrieves the list of configuration files containing system properties to be set. The system properties must be set in the same order as they are returned here.- Parameters:
opennmsHome
- the OpenNMS home directory- Returns:
- a list of property files
-
loadSystemProperties
protected static void loadSystemProperties(File opennmsHome) throws IOException
Load default properties from the specified OpenNMS home into the system properties.- Parameters:
opennmsHome
- the OpenNMS home directory- Throws:
IOException
-
isValidOpenNMSHome
protected static boolean isValidOpenNMSHome(File opennmsHome)
Validates the OpenNMS home directory by checking for known mandatory files.- Parameters:
opennmsHome
- the OpenNMS home directory- Returns:
- true is the opennmsHome folder is a valid OpenNMS home directory
-
findOpenNMSHome
protected static File findOpenNMSHome() throws Exception
Find the OpenNMS home directory.- Throws:
Exception
-
findOpenNMSHomeUsingJarPath
public static File findOpenNMSHomeUsingJarPath()
Determine the OpenNMS home directory based on the location of the JAR file containing this code. Finds the JAR file containing this code, and if it is found, the file name of the JAR (e.g.: opennms_bootstrap.jar) and its parent directory (e.g.: the lib directory) are removed from the path and the resulting path (e.g.: /opt/OpenNMS) is returned.- Returns:
- Home directory or null if it couldn't be found
-
main
public static void main(String[] args) throws Exception
Bootloader main method. Takes the following steps to initialize a ClassLoader, set properties, and start OpenNMS:- Checks for existence of opennms.home system property, and loads properties file located at ${opennms.home}/etc/bootstrap.properties if it exists.
- Calls
findOpenNMSHome
to determine the OpenNMS home directory if the bootstrap.properties file has not yet been loaded. Sets the opennms.home system property to the path returned from findOpenNMSHome. - Calls
loadClasses
to create a new ClassLoader. ${opennms.home}/etc and ${opennms.home}/lib are passed to loadClasses. - Determines the proper default value for configuration options when
overriding system properties have not been set. Below are the default
values.
- opennms.library.jicmp: ClassLoader.getResource(System.mapLibraryName("jicmp"))
- opennms.library.jrrd: ClassLoader.getResource(System.mapLibraryName("jrrd"))
- log4j.configuration: "log4j.properties"
- jcifs.properties: ClassLoader.getResource("jcifs.properties")
- Finally, the main method of org.opennms.netmgt.vmmgr.Controller is invoked with the parameters passed in argv.
- Parameters:
args
- Command line arguments- Throws:
Exception
- if any.
-
executeClass
protected static void executeClass(String classToExec, String classToExecMethod, String[] classToExecArgs, boolean appendClasspath) throws ClassNotFoundException, NoSuchMethodException, IOException
-
executeClass
protected static void executeClass(String classToExec, String classToExecMethod, String[] classToExecArgs, boolean appendClasspath, boolean recurse) throws ClassNotFoundException, NoSuchMethodException, IOException
-
-