Skip to content

Commit

Permalink
[DSIP-27][Task Plugin] Some improvements of JAVA task plugin (#16542)
Browse files Browse the repository at this point in the history
  • Loading branch information
ailiujiarui authored Dec 9, 2024
1 parent 80c5f59 commit cad8df0
Show file tree
Hide file tree
Showing 23 changed files with 778 additions and 398 deletions.
28 changes: 21 additions & 7 deletions docs/docs/en/guide/task/java.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Overview

This node is for executing java-type tasks and supports using files and jar packages as program entries.
This node is used to execute tasks of the `Java` type and supports running `jar` packages of the `FAT_JAR` and `NORMAL_JAR` types.

# Create Tasks

Expand All @@ -20,24 +20,38 @@ This node is for executing java-type tasks and supports using files and jar pack
| Module Path | pick Java 9 + 's modularity feature, put all resources into-module-path, and require that the JDK version in your worker supports modularity. |
| Main Parameter | Java program main method entry parameter. |
| Java VM Parameters | JVM startup parameters. |
| Script | You need to write Java code if you use the Java run type. The public class must exist in the code without writing a package statement. |
| Main Class Name | Fully Qualified Name of the Main Class (Optional) |
| Main Package | Select the main program package to run the application. |
| Resources | External JAR packages or other resource files that are added to the classpath or module path and can be easily retrieved in your JAVA script. |

## Example

Java type tasks have two modes of execution, here is a demonstration of executing tasks in Java mode.
There are two execution modes for Java task types, which will be demonstrated separately here.

The main configuration parameters are as follows:
- Run Type
- Module Path
- Main Parameters
- Java VM Parameters
- Script
- Main Package
- Resources

![java_task](../../../../img/tasks/demo/java_task02.png)
As shown in the figure.

- FAT_JAR

![java_task](../../../../img/tasks/demo/java_fat.png)

`FAT_JAR` is also known as `uber-jar`, where the dependencies and code are contained within the same `jar`. You only need to select this one `jar`.

- NORMAL_JAR

![java_task](../../../../img/tasks/demo/java_normal.png)

`normal1.jar` is the entry point of the program, and `normal2.jar` contains the required dependencies. The entry point of the program must be specified in the main program package, and all the dependencies along with the program entry `jar` files should be selected in the resource file to ensure correct execution.

## Note

When you run the task in JAVA execution mode, the public class must exist in the code, and you could omit writing a package statement.
1. For security reasons, when executing JAVA tasks, please use the environment management module to configure the JDK environment, such as `JAVA_HOME` and other environment variables.
2. NORMAL_JAR should provide the main class name (optional), while FAT_JAR does not need to provide the main class name.

For security reasons, when executing JAVA tasks, please use the environment management module to configure the JDK environment, such as `JAVA_HOME` and other environment variables.
28 changes: 21 additions & 7 deletions docs/docs/zh/guide/task/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 综述

该节点用于执行 java 类型的任务,支持使用单文件和jar包作为程序入口
该节点用于执行`Java`类型的任务,支持使用`FAT_JAR`类型和`NORMAL_JAR`类型的`jar`包运行

## 创建任务

Expand All @@ -22,25 +22,39 @@
| 模块路径 | 开启使用JAVA9+的模块化特性,把所有资源放入--module-path中,要求您的worker中的JDK版本支持模块化 |
| 主程序参数 | 作为普通Java程序main方法入口参数 |
| 虚拟机参数 | 配置启动虚拟机参数 |
| 脚本 | 若使用JAVA运行类型则需要编写JAVA代码。代码中必须存在public类,不用写package语句 |
| 主类名 | 启动类的完整主类名(可选) |
| 主程序包 | 选择要运行程序的主程序包 |
| 资源 | 可以是外部JAR包也可以是其他资源文件,它们都会被加入到类路径或模块路径中,您可以在自己的JAVA脚本中轻松获取 |

## 任务样例

java任务类型有两种运行模式,这里以JAVA模式为例进行演示
java任务类型有两种运行模式,这里进行分别进行演示

主要配置参数如下:

- 运行类型
- 模块路径
- 主程序参数
- 虚拟机参数
- 脚本文件
- 主程序包
- 资源文件

![java_task](../../../../img/tasks/demo/java_task02.png)
如图所示

- FAT_JAR类型

![java_task](../../../../img/tasks/demo/java_fat.png)

`FAT_JAR``uber-jar`,依赖和代码都在同一个`jar`中,只需选择这一个`jar`即可

- NORMAL_JAR类型

![java_task](../../../../img/tasks/demo/java_normal.png)

`normal1.jar`是程序运行的入口,`normal2.jar`是所需的依赖,需要用主程序包指定程序的入口,并且在资源文件中选择所有依赖和程序入口的`jar`文件,才能正确运行

## 注意事项

使用JAVA运行类型时代码中必须存在public类,可以不写package语句
1. 基于安全原因,执行JAVA任务时,请使用环境管理功能配置JDK环境,例如`JAVA_HOME`等环境变量
2. `NORMAL_JAR` 应该提供主类名(可选),`FAT_JAR` 不需要提供主类名。

基于安全原因,执行JAVA任务时,请使用环境管理功能配置JDK环境,例如`JAVA_HOME`等环境变量
Binary file added docs/img/tasks/demo/java_fat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/tasks/demo/java_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/img/tasks/demo/java_task02.png
Binary file not shown.
Loading

0 comments on commit cad8df0

Please sign in to comment.