Browse Source

[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>
lizhenglei 1 year ago
parent
commit
bd48c99178

+ 1 - 1
dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/java/org/apache/dolphinscheduler/plugin/task/java/JavaTask.java

@@ -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)

+ 3 - 3
dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/test/java/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java

@@ -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);