-
-
Notifications
You must be signed in to change notification settings - Fork 184
Closed
Description
Options set in JBANG_JAVA_OPTIONS are passed to the JVM that JBang creates to run a particular Java/Kotlin/Groovy script.
bash-3.2$ export JBANG_JAVA_OPTIONS=-XX:TieredStopAtLevel=1
bash-3.2$ jbang run JvmRuntimeOpts.java 1 2 3
--- π JVM Runtime Options (VM Arguments) ---
Option 1: -XX:TieredStopAtLevel=1
--- π Application Arguments ---
Argument 1: 1
Argument 2: 2
Argument 3: 3
import java.lang.management.ManagementFactory;
import java.util.List;
/**
* JvmRuntimeOpts.java
* This program demonstrates how to retrieve and display:
* 1. JVM Runtime Options (VM arguments).
* 2. Application Arguments (arguments passed to the main method).
*/
public class JvmRuntimeOpts {
public static void main(String[] args) {
// --- 1. Display JVM Runtime Options ---
System.out.println("--- π JVM Runtime Options (VM Arguments) ---");
// Use the ManagementFactory to get the RuntimeMXBean
List<String> jvmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
if (jvmArgs.isEmpty()) {
System.out.println("No explicit JVM Runtime Options found (default settings are in use).");
} else {
for (int i = 0; i < jvmArgs.size(); i++) {
System.out.println("Option " + (i + 1) + ": " + jvmArgs.get(i));
}
}
System.out.println("\n" + "--- π Application Arguments ---");
// --- 2. Display Application Arguments ---
if (args.length == 0) {
System.out.println("No Application Arguments were passed to the main method.");
} else {
for (int i = 0; i < args.length; i++) {
System.out.println("Argument " + (i + 1) + ": " + args[i]);
}
}
System.out.println("\n" + "--- β
Execution Complete ---");
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels