@Component
public final class JarUtilities
extends java.lang.Object
| Constructor and Description |
|---|
JarUtilities() |
| Modifier and Type | Method and Description |
|---|---|
void |
copyFileFromJar(java.lang.String fileToCopy,
boolean replaceIfExists,
java.lang.Class<?> classToCopyFrom)
Copy a file from inside our JAR-file to the host filesystem.
|
boolean |
copyFileFromJar(java.lang.String fileToCopy,
java.lang.Class<?> identifierClass)
Copy a file from inside our JAR-file to the host filesystem.
|
void |
copyFileFromJar(java.lang.String fileToCopy,
java.io.File destinationFile,
boolean replaceIfExists,
java.lang.Class<?> identifierClass)
Copy a file from inside our JAR-file to the host filesystem to the specified destination,
replacing an already existing file.
|
boolean |
copyFileFromJar(java.lang.String fileToCopy,
java.io.File destinationFile,
java.lang.Class<?> identifierClass)
Copy a file from inside our JAR-file to the host filesystem to the specified destination.
|
void |
copyFolderFromJar(java.lang.Class<?> classToRetrieveHomeFor,
java.lang.String directoryToCopy,
java.lang.String destinationDirectory,
java.lang.String jarDirectoryPrefix,
java.lang.String fileEnding)
Copy a folder from inside a JAR-file to the host filesystem.
|
org.springframework.boot.system.ApplicationHome |
getApplicationHomeForClass(java.lang.Class<?> classToRetrieveHomeFor)
Retrieve the ApplicationHome for a given class.
|
java.util.HashMap<java.lang.String,java.lang.String> |
systemInformation(org.springframework.boot.system.ApplicationHome applicationHome)
Retrieve information about the environment for the given instance of
ApplicationHome,
stored in a HashMap.Available key-value-pairs: jarPath - The path to the JAR-file. jarName - The name of the JAR-file. javaVersion - The version of the Java installation used. osArch - Architecture of the system. osName - Name of the operating system. osVersion - Version of the operating system. |
public void copyFileFromJar(java.lang.String fileToCopy,
boolean replaceIfExists,
java.lang.Class<?> classToCopyFrom)
copyFileFromJar(new File("log4j2.xml"))
will result in the log4j2.xml file from inside the JAR-file to be copied to the outside of the
JAR-file as log4j2.xmlfileToCopy - File. The source-file in the JAR you wish to copy outside the JAR.replaceIfExists - Boolean. Whether to replace the file, if it already exists.classToCopyFrom - Class. The class of the JAR from which you want to copy from.public boolean copyFileFromJar(java.lang.String fileToCopy,
java.lang.Class<?> identifierClass)
copyFileFromJar(new File("log4j2.xml")) will result in the log4j2.xml file from inside
the JAR-file to be copied to the outside of the JAR-file as log4j2.xmlfileToCopy - The source-file in the JAR you wish to copy outside the JAR.identifierClass - The class of the JAR from which to get the resource.true if the file was created, false otherwise.public void copyFileFromJar(java.lang.String fileToCopy,
java.io.File destinationFile,
boolean replaceIfExists,
java.lang.Class<?> identifierClass)
copyFileFromJar(new File("log4j2.xml"))
will result in the log4j2.xml file from inside the JAR-file to be copied to the outside of the
JAR-file as log4j2.xmlfileToCopy - The source-file in the JAR you wish to copy outside the JAR.destinationFile - The file to which to copy to.identifierClass - The class of the JAR from which to get the resource.replaceIfExists - Boolean. Whether to replace the file, if it already exists.public boolean copyFileFromJar(java.lang.String fileToCopy,
java.io.File destinationFile,
java.lang.Class<?> identifierClass)
copyFileFromJar(new File("log4j2.xml")) will result in the log4j2.xml file from inside
the JAR-file to be copied to the outside of the JAR-file as log4j2.xmlfileToCopy - The source-file in the JAR you wish to copy outside the JAR.identifierClass - The class of the JAR from which to get the resource.destinationFile - The file to which to copy to.true if the file was created, false otherwise.public org.springframework.boot.system.ApplicationHome getApplicationHomeForClass(java.lang.Class<?> classToRetrieveHomeFor)
classToRetrieveHomeFor - The class to retrieve the ApplicationHome for.ApplicationHome for the given class.public java.util.HashMap<java.lang.String,java.lang.String> systemInformation(org.springframework.boot.system.ApplicationHome applicationHome)
ApplicationHome,
stored in a HashMap.applicationHome - Instance of ApplicationHome from which to gather information
about the JAR-file and system.public void copyFolderFromJar(java.lang.Class<?> classToRetrieveHomeFor,
java.lang.String directoryToCopy,
java.lang.String destinationDirectory,
java.lang.String jarDirectoryPrefix,
java.lang.String fileEnding)
throws java.io.IOException
classToRetrieveHomeFor - Path to either the JAR-file from which to copy a folder from, or
to the class when running in a dev-environment. This parameter
decides whether
copyFolderFromJar(Class, String, String, String) or
copyFolderFromJar(JarFile, String, String, String,
String) is called./home/griefed/serverpackcreator/serverpackcreator.jar
G:/GitLab/ServerPackCreator/build/classes/java/main ServerPackCreator.main(String[]) source code for an
example on how this is acquired automatically.directoryToCopy - Path to the directory inside the JAR-file you want to copy.destinationDirectory - Path to the destination directory you want to copy source to.jarDirectoryPrefix - A prefix to remove when checking for existence of source inside
the JAR-file. For example, the ServerPackCreator files inside
it's JAR-File are located in BOOT-INF/classes due to
SpringBoot. In order to correctly scan for source, we need to
remove that prefix, so we receive a path that looks like a
regular path inside a JAR-file.fileEnding - The file-ending to filter for.java.io.IOException - Exception thrown if a file can not be accessed, found or otherwise worked
with.