home / skills / windmill-labs / windmill / write-script-java
This skill helps you write Java scripts with a standardized Main class, enabling structured input handling and JSON-friendly outputs.
npx playbooks add skill windmill-labs/windmill --skill write-script-javaReview the files below or copy the command above to add this skill to your agents.
---
name: write-script-java
description: MUST use when writing Java scripts.
---
## CLI Commands
Place scripts in a folder. After writing, run:
- `wmill script generate-metadata` - Generate .script.yaml and .lock files
- `wmill sync push` - Deploy to Windmill
Use `wmill resource-type list --schema` to discover available resource types.
# Java
The script must contain a Main public class with a `public static main()` method:
```java
public class Main {
public static Object main(String name, int count) {
java.util.Map<String, Object> result = new java.util.HashMap<>();
result.put("name", name);
result.put("count", count);
return result;
}
}
```
**Important:**
- Class must be named `Main`
- Method must be `public static Object main(...)`
- Return type is `Object` or `void`
## Maven Dependencies
Add dependencies using comments at the top:
```java
//requirements:
//com.google.code.gson:gson:2.10.1
//org.apache.httpcomponents:httpclient:4.5.14
import com.google.gson.Gson;
public class Main {
public static Object main(String input) {
Gson gson = new Gson();
return gson.fromJson(input, Object.class);
}
}
```
This skill provides concise rules and examples for writing Java scripts that run on the platform. It explains required class/method signatures, how to declare Maven dependencies inline, and the CLI steps to generate metadata and deploy scripts. Follow these conventions to ensure the platform recognizes and executes your Java script correctly.
The platform expects a single public class named Main with a public static Object main(...) method (or void). You can return any serializable object or void. Maven dependencies are declared using special comment lines at the top of the file, which the build system reads to fetch required libraries. After authoring, run the provided CLI commands to generate metadata and push the script to the platform.
What must the class and method be named?
The class must be named Main and the entry must be public static Object main(...) or public static void main(...).
How do I add external libraries?
List Maven coordinates at the top of the file using comment lines that start with //requirements:group:artifact:version. The build system reads these to fetch dependencies.