Skip to content

Options in JBANG_APP_JAVA_OPTIONS are duplicated for every file referenced in //SOURCES #2361

@wfouche

Description

@wfouche

To reproduce:

set JBANG_APP_JAVA_OPTIONS=-Xms1g -Xmx2g -XX:+UseZGC
jbang run JvmRuntimeOpts.java
--- 🚀 JVM Runtime Options (VM Arguments) ---
Option 1: -Xms1g
Option 2: -Xmx2g
Option 3: -XX:+UseZGC
Option 4: -Xms1g
Option 5: -Xmx2g
Option 6: -XX:+UseZGC
Option 7: -Xms1g
Option 8: -Xmx2g
Option 9: -XX:+UseZGC
Option 10: --enable-preview

A.java

class A {}

B.java

class B {}

JvmRuntimeOpts.java

//PREVIEW 
//SOURCES A.java B.java
import java.lang.management.ManagementFactory;
import java.util.List;

/**
 * JvmRuntimeOps.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 ---");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions