From c6623ab312d231e2b64f3b83207cc72156cc9223 Mon Sep 17 00:00:00 2001 From: Karl Kauc Date: Fri, 28 Aug 2026 17:43:11 +0200 Subject: [PATCH] docs(xsd-java): run XsdValidate.java via the JDK source launcher, no Maven needed XsdValidate.java has no dependency beyond the JDK (javax.xml.validation + java.net.http), so JDK 11+ can compile and run it directly (JEP 330): java XSD_Validation/java/XsdValidate.java Document this as the primary invocation in the class header, the module pom.xml comment, XSD_Validation/README.md and the root README; keep the Maven aggregator path as the alternative that CI uses. Also fix the pom.xml comment, which still described the pre-#21 version resolution (env var / cache / "4.2.9" arg). Robustness: a missing, unreadable or malformed schema now exits 2 with a one-line message instead of stack-tracing out with exit 1, matching the documented exit codes (0 valid / 1 invalid / 2 usage or setup error). Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01YXZWhwE5EbHSybt55K6oUZ --- README.md | 2 +- XSD_Validation/README.md | 12 ++++++++++- XSD_Validation/java/XsdValidate.java | 30 ++++++++++++++++++++++++---- XSD_Validation/java/pom.xml | 13 ++++++++---- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ac4a1ee..f063694 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ XSD=https://github.com/fundsxml/schema/releases/download/4.2.9/FundsXML.xsd # XSD validation — pick any stack (schema + xml, schema-first): python XSD_Validation/python/validate.py "$XSD" $SRC dotnet run --project XSD_Validation/dotnet -- "$XSD" $SRC -./mvnw -q -pl XSD_Validation/java compile exec:java -Dexec.args="$XSD $SRC" +java XSD_Validation/java/XsdValidate.java "$XSD" $SRC # JDK 11+ only, no Maven needed XSD_Validation/cli/validate.sh "$XSD" $SRC # Windows: pwsh .../validate.ps1 # Schematron business rules (SVRL; exit 0 = no ERROR-role failures) diff --git a/XSD_Validation/README.md b/XSD_Validation/README.md index cde6a95..20e53db 100644 --- a/XSD_Validation/README.md +++ b/XSD_Validation/README.md @@ -78,7 +78,17 @@ python XSD_Validation/python/validate.py "$REL" FundsXML_Files/4.2.9/positions/M python XSD_Validation/python/validate.py "$REL" tests/fixtures/invalid/xsd-invalid_Positions.xml # exit 1 ``` -Java (standalone): `./mvnw -q -pl XSD_Validation/java compile exec:java -Dexec.args="$REL "` +Java (standalone, JDK 11+ only — no Maven needed, the example has no +dependencies beyond the JDK): + +```bash +java XSD_Validation/java/XsdValidate.java "$REL" FundsXML_Files/4.2.9/positions/Mixed-Fund_Positions.xml # exit 0 +java XSD_Validation/java/XsdValidate.java "$REL" tests/fixtures/invalid/xsd-invalid_Positions.xml # exit 1 +``` + +(Windows: `java XSD_Validation\java\XsdValidate.java `.) +The same class also runs through the Maven aggregator, which is what CI uses: +`./mvnw -q -pl XSD_Validation/java compile exec:java -Dexec.args="$REL "` (`mvnw.cmd` on Windows). .NET (standalone): `dotnet run --project XSD_Validation/dotnet -- "$REL" ` diff --git a/XSD_Validation/java/XsdValidate.java b/XSD_Validation/java/XsdValidate.java index 2cd26af..177a952 100644 --- a/XSD_Validation/java/XsdValidate.java +++ b/XSD_Validation/java/XsdValidate.java @@ -1,10 +1,19 @@ // XSD validation in native Java (no JAXB) via javax.xml.validation. // // Standalone & cross-platform — no prior tool, no bash, works on Windows. -// Run from the repo root with the committed Maven Wrapper: +// The only dependency is the JDK itself (javax.xml.validation + java.net.http), +// so no build tool is needed: JDK 11+ compiles and runs a single source file +// directly (JEP 330). Run from the repo root: +// java XSD_Validation/java/XsdValidate.java \ +// https://github.com/fundsxml/schema/releases/download/4.2.9/FundsXML.xsd \ +// FundsXML_Files/4.2.9/positions/Mixed-Fund_Positions.xml +// (Windows: java XSD_Validation\java\XsdValidate.java ) +// +// Alternatively via the committed Maven Wrapper (the module is part of the +// root aggregator so `./mvnw compile` builds it together with the other +// examples; it has no dependencies of its own): // ./mvnw -q -pl XSD_Validation/java compile exec:java \ -// -Dexec.args="https://github.com/fundsxml/schema/releases/download/4.2.9/FundsXML.xsd \ -// FundsXML_Files/4.2.9/positions/Mixed-Fund_Positions.xml" +// -Dexec.args=" " // Exit: 0 = valid, 1 = invalid, 2 = usage/setup error // // You give it exactly two things: the schema and the instance. is a @@ -79,13 +88,26 @@ public static void main(String[] args) throws Exception { factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "file"); factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); - Schema fundsXmlSchema = factory.newSchema(schemaFile); + // A missing, unreadable or malformed *schema* is a setup error + // (exit 2), not an invalid instance (exit 1) — report it in one + // line instead of letting the SAXParseException stack-trace out. + Schema fundsXmlSchema; + try { + fundsXmlSchema = factory.newSchema(schemaFile); + } catch (SAXParseException e) { + System.err.println("cannot load schema " + schemaArg + ": " + + e.getMessage()); + System.exit(2); + return; + } Validator validator = fundsXmlSchema.newValidator(); validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "file"); final boolean[] failed = {false}; validator.setErrorHandler(new ErrorHandler() { + // Schema warnings (e.g. unused imports) never affect + // validity — deliberately ignored to keep the output clean. public void warning(SAXParseException e) { } public void error(SAXParseException e) { report(e); } public void fatalError(SAXParseException e) { report(e); } diff --git a/XSD_Validation/java/pom.xml b/XSD_Validation/java/pom.xml index 688c608..1726668 100644 --- a/XSD_Validation/java/pom.xml +++ b/XSD_Validation/java/pom.xml @@ -1,12 +1,17 @@