[BUG][Task] fix java task classpath (#15470)

* fix javatask bug

* cover

---------

Co-authored-by: 80597928 <673421862@qq.com>
Co-authored-by: fuchanghai <changhaifu@apache.org>
This commit is contained in:
lizhenglei 2024-01-12 14:39:59 +08:00 committed by GitHub
parent 0f7081be10
commit bd48c99178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -280,7 +280,7 @@ public class JavaTask extends AbstractTask {
if (javaParameters.isModulePath()) {
builder.append("--module-path");
} else {
builder.append("--class-path");
builder.append("-classpath");
}
builder.append(" ")
.append(JavaConstants.CLASSPATH_CURRENT_DIR)

View File

@ -84,7 +84,7 @@ public class JavaTaskTest {
String homeBinPath = JavaConstants.JAVA_HOME_VAR + File.separator + "bin" + File.separator;
JavaTask javaTask = runJarType();
Assertions.assertEquals(javaTask.buildJarCommand(), homeBinPath
+ "java --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar -jar /tmp/dolphinscheduler/test/executepath/opt/share/jar/main.jar -host 127.0.0.1 -port 8080 -xms:50m");
+ "java -classpath .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar -jar /tmp/dolphinscheduler/test/executepath/opt/share/jar/main.jar -host 127.0.0.1 -port 8080 -xms:50m");
}
/**
@ -106,7 +106,7 @@ public class JavaTaskTest {
Files.delete(path);
}
Assertions.assertEquals(homeBinPath
+ "javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java",
+ "javac -classpath .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java",
javaTask.buildJavaCompileCommand(sourceCode));
} finally {
Path path = Paths.get(fileName);
@ -125,7 +125,7 @@ public class JavaTaskTest {
@Test
public void buildJavaCommand() throws Exception {
String wantJavaCommand =
"${JAVA_HOME}/bin/javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java;${JAVA_HOME}/bin/java --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar JavaTaskTest -host 127.0.0.1 -port 8080 -xms:50m";
"${JAVA_HOME}/bin/javac -classpath .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java;${JAVA_HOME}/bin/java -classpath .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar JavaTaskTest -host 127.0.0.1 -port 8080 -xms:50m";
JavaTask javaTask = runJavaType();
String sourceCode = javaTask.buildJavaSourceContent();
String publicClassName = javaTask.getPublicClassName(sourceCode);