дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 19:25:54 +02:00
fix(run): run single Java files whose main class is not the first top-level type (#1417)
A Java file outside a Maven / Gradle build ran as `java File.java` (JEP 330), which launches the file's first top-level type on JDK 21 and earlier. A file whose main is in a later class failed with "can't find main(String[]) method in class: Parent", and the gutter Run of a second or nested class's main launched the first class. Such files now compile with the JDK's own `javac -g -d <class dir>` and run `java -cp <class dir> <main class>`; a main in the first class, and compact source files, still use the source launcher. Debug passes the JDWP agent through JDK_JAVA_OPTIONS, which only the java launcher reads. Co-authored-by: ldg030201 <[email protected]>
Цей коміт міститься в:
1 джерело
e129840651
коміт
54502e0a17
5 files changed
+158
-5
No files matched your search
@@ -40,8 +40,12 @@ function withProperty(args: readonly string[], key: string, value: string): stri
|
||||
export function jdwpLaunch(config: RunConfig): RunConfig | null {
|
||||
if (config.kind === "tomcat") return { ...config, params: { ...config.params, tomcatDebug: "true" } };
|
||||
const args = config.args;
|
||||
// A single source file (`java Hi.java`): the agent goes before the file.
|
||||
if (config.kind === "java-file") return { ...config, args: [JDWP_AGENT, ...args] };
|
||||
// A single source file (`java Hi.java`): the agent goes before the file. Compiled first
|
||||
// (`javac … && java -cp …`): through `JDK_JAVA_OPTIONS`, which only the `java` launcher reads.
|
||||
if (config.kind === "java-file")
|
||||
return args.length
|
||||
? { ...config, args: [JDWP_AGENT, ...args] }
|
||||
: { ...config, env: withOption(config.env, "JDK_JAVA_OPTIONS", JDWP_AGENT) };
|
||||
if (config.kind === "maven" || /(^|\/)mvnw?(\.cmd)?$/.test(config.command)) {
|
||||
if (args.some((a) => a === "spring-boot:run" || /:spring-boot-maven-plugin:[^:]*:run$/.test(a)))
|
||||
return { ...config, args: withProperty(args, "spring-boot.run.jvmArguments", JDWP_AGENT) };
|
||||
|
||||
Reference in new issue
Заблокувати користувача