diff --git a/src/java.base/share/classes/sun/launcher/resources/launcher.properties b/src/java.base/share/classes/sun/launcher/resources/launcher.properties --- a/src/java.base/share/classes/sun/launcher/resources/launcher.properties +++ b/src/java.base/share/classes/sun/launcher/resources/launcher.properties @@ -62,6 +62,8 @@ \ list the observable modules and exit\n\ \ -D=\n\ \ set a system property\n\ +\ -dryrun\n\ +\ create VM but do not execute main class\n\ \ -verbose:[class|gc|jni]\n\ \ enable verbose output\n\ \ -version print product version and exit\n\ diff --git a/src/java.base/share/native/libjli/java.c b/src/java.base/share/native/libjli/java.c --- a/src/java.base/share/native/libjli/java.c +++ b/src/java.base/share/native/libjli/java.c @@ -68,7 +68,8 @@ static jboolean showVersion = JNI_FALSE; /* print but continue */ static jboolean printUsage = JNI_FALSE; /* print and exit*/ static jboolean printXUsage = JNI_FALSE; /* print and exit*/ -static char *showSettings = NULL; /* print but continue */ +static jboolean dryRun = JNI_FALSE; /* initialize VM and exit */ +static char *showSettings = NULL; /* print but continue */ static char *listModules = NULL; static const char *_program_name; @@ -488,14 +489,18 @@ mainArgs = CreateApplicationArgs(env, argv, argc); CHECK_EXCEPTION_NULL_LEAVE(mainArgs); - /* Invoke main method. */ - (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs); + if (dryRun) { + ret = 0; + } else { + /* Invoke main method. */ + (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs); - /* - * The launcher's exit code (in the absence of calls to - * System.exit) will be non-zero if main threw an exception. - */ - ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1; + /* + * The launcher's exit code (in the absence of calls to + * System.exit) will be non-zero if main threw an exception. + */ + ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1; + } LEAVE(); } @@ -1198,6 +1203,8 @@ return JNI_TRUE; } else if (JLI_StrCmp(arg, "-showversion") == 0) { showVersion = JNI_TRUE; + } else if (JLI_StrCmp(arg, "-dryrun") == 0) { + dryRun = JNI_TRUE; } else if (JLI_StrCmp(arg, "-X") == 0) { printXUsage = JNI_TRUE; return JNI_TRUE;