You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by "ailiujiarui (via GitHub)" <gi...@apache.org> on 2024/12/02 03:30:01 UTC

Re: [PR] [DSIP-27][Task Plugin] Some improvements of JAVA task plugin [dolphinscheduler]

ailiujiarui commented on code in PR #16542:
URL: https://github.com/apache/dolphinscheduler/pull/16542#discussion_r1862898174


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/java/org/apache/dolphinscheduler/plugin/task/java/JavaTask.java:
##########
@@ -150,44 +133,45 @@ public void handle(TaskCallBack taskCallBack) throws TaskException {
     }
 
     /**
-     * Construct a shell command for the java Run mode
+     * Construct a shell command for the java -jar Run mode
      *
      * @return String
-     * @throws Exception
      **/
-    protected String buildJavaCommand() throws Exception {
+    protected String buildJarCommand() {
+        ResourceContext resourceContext = taskRequest.getResourceContext();
+        String mainJarAbsolutePathInLocal = resourceContext
+                .getResourceItem(javaParameters.getMainJar().getResourceName())
+                .getResourceAbsolutePathInLocal();
         StringBuilder builder = new StringBuilder();
-        String sourceCode = buildJavaSourceContent();
-        builder.append(buildJavaCompileCommand(sourceCode))
-                .append(";")
-                .append(getJavaCommandPath())
-                .append("java").append(" ")
-                .append(buildResourcePath())
-                .append(" ")
-                .append(getPublicClassName(sourceCode))
-                .append(" ")
-                .append(javaParameters.getMainArgs().trim()).append(" ")
+        builder.append(getJavaCommandPath())
+                .append("java").append(Constants.SPACE)
+                .append(buildResourcePath()).append(Constants.SPACE)
+                .append("-jar").append(Constants.SPACE)
+                .append(mainJarAbsolutePathInLocal).append(Constants.SPACE)
+                .append(javaParameters.getMainArgs().trim()).append(Constants.SPACE)
                 .append(javaParameters.getJvmArgs().trim());
         return builder.toString();
     }
 
     /**
-     * Construct a shell command for the java -jar Run mode
+     * Construct a shell command for the java -cp run mode
      *
      * @return String
      **/
-    protected String buildJarCommand() {
+    protected String buildNormalJarCommand() {
         ResourceContext resourceContext = taskRequest.getResourceContext();
-        String mainJarAbsolutePathInLocal = resourceContext
-                .getResourceItem(javaParameters.getMainJar().getResourceName())
+        String mainJarAbsolutePathInLocal = resourceContext.getResourceItem(
+                javaParameters.getMainJar()
+                        .getResourceName())
                 .getResourceAbsolutePathInLocal();
+        String mainJarName = MainClassExtractor.getMainClassName(mainJarAbsolutePathInLocal);

Review Comment:
   Do you mean that users should input the main class name themselves? Currently, the method reads the main class from the JAR's META-INF file. I believe this approach eliminates the need for configuration steps, allowing users to simply select the JAR and run it directly. Could you please explain why users should be required to input the main class name themselves?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org