# manage-java > Implement OFBiz services in Java. Use when writing core domain logic, strict typing, or performance-critical code. - Author: toaditi - Repository: toaditi/ofbiz-dev-agent-skills - Version: 20260124175846 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/toaditi/ofbiz-dev-agent-skills - Web: https://mule.run/skillshub/@@toaditi/ofbiz-dev-agent-skills~manage-java:20260124175846 --- --- name: manage-java description: Implement OFBiz services in Java. Use when writing core domain logic, strict typing, or performance-critical code. --- # Skill: manage-java (v1.0) ## Goal Implement OFBiz services in Java. ## Triggers **ALWAYS** read this skill when: - Creating a new Java service. - Implementing complex domain logic requiring strict typing. - Debugging Java compilation errors in plugins. ## Use when - Reusable libraries / Core domain logic. - Strict typing/contracts required. - Performance critical. ## Don't use when - Simple orchestration (use MiniLang). - Data adaptation/transformation (use Groovy). ## Inputs - required: `DispatchContext`, `Map context` ## Outputs - `Map` ## Procedure 1. Create `src/main/java/[Package]/[Name]Services.java`. 2. **Structure**: Use a static class with static methods matching `invoke` attribute. - Define `public static final String MODULE = [Name]Services.class.getName();` 3. Define `public static Map myService(DispatchContext dctx, Map context)`. 4. **Helpers**: - `Delegator delegator = dctx.getDelegator();` (Use `EntityQuery` for DB). - `LocalDispatcher dispatcher = dctx.getDispatcher();` 5. **Logic**: - Warp all logic in `try { ... } catch (Exception e) { ... }`. - Log errors: `Debug.logError(e, "Msg", MODULE);` 6. Return: `ServiceUtil.returnSuccess()` or `ServiceUtil.returnError()`. ## Guardrails - **Signature**: Must match exactly or reflection fails. - **Boilerplate**: Don't use for trivial CRUD. - **Logging**: Use `Debug.logInfo(msg, MODULE)`. ## Failure handling - **Exceptions**: Catch and return `ServiceUtil.returnError(e.getMessage())`. ## Examples **Example A (Calculation)**: Input: calculateTax Output: ```java public static Map calculateTax(DispatchContext dctx, Map context) { Delegator delegator = dctx.getDelegator(); try { Double amount = (Double) context.get("amount"); if (amount == null) return ServiceUtil.returnError("Amount missing"); GenericValue settings = EntityQuery.use(delegator).from("TaxSettings").where("id", "MAIN").cache(true).queryOne(); Map res = ServiceUtil.returnSuccess(); res.put("tax", amount * 0.1); return res; } catch (Exception e) { Debug.logError(e, "Error calculating tax", MODULE); return ServiceUtil.returnError("Error: " + e.getMessage()); } } ```