Running a spring boot jar file with the given GC configuration
- -Xloggc:/file/path/gc.log
- -XX:+PrintGCTimeStamps
- -XX:+PrintGCDateStamps
- -XX:+PrintGCDetails
But, instead of passing all this GC information data in the command line when we are running the jar like
java -Dspring.profiles.active=<env-name> -Xmx5G -Xms2G -XX:MaxMetaspaceSize=2G -XX:+UseG1GC -Xloggc:/file/path/gc.log -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintGCDetails -jar application.jar
Is there any other approach that I can use to read the configuration from external file and pass it to jar
Edit :
As Slaw mentioned in the comment of using java Command-Line Argument Files
Created a file with args
as name & the data it has is
-Dspring.profiles.active=<env-name> -Xmx5G -Xms2G -XX:MaxMetaspaceSize=2G -XX:+UseG1GC -Xloggc:/file/path/gc.log -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintGCDetails -jar application.jar
by running the jar like
java @args
getting error as
Error: Could not find or load main class @args
It was not able to find the Main class. I think it was not identifying the jar in the args
file.
If you are using Java 9 and later, command line argument files (@file1
) should work1.
Another option for Java 9 and later is to set the JDK_JAVA_OPTIONS
environment variable. This gives a list of options that will be automatically prepended to the java
command line's JVM options.
For Java 8 and earlier, your options are more limited:
Write a shell wrapper script, shell function or shell alias for either the
java
command or your application's command line.Explicitly add an environment variable when you use the
java
command; e.g.$ java $STD_OPTS my.app.Main args ...
You could conceivably implement a custom launcher (in C) an have that do clever things such as emulating Java 9's @file mechanism.
1 - Based on the symptoms, I think your attempt with @file
failed either because the file was not found in the appropriate directory, or because you are using Java 8 or earlier.