Class X2JMain

java.lang.Object
com.x2j.converter.main.X2JMain

public class X2JMain extends Object
This is the main class that will run when the x2j jar file is executed from command line.
The only mandatory argument that is required is the input XML file path.
If the JSON schema file path is passed as an argument, then that will be used for conversion, otherwise the default conversion logic will be applied.
For more information on JSON schema definition, please visit: XML-To-JSON Converter
Additionally, if the output file path is passed as an argument, then the output converted JSON will be saved in the specified file, otherwise the converted JSON will be printed in the console.
  • Constructor Details

    • X2JMain

      public X2JMain()
  • Method Details

    • main

      public static void main(String[] args) throws X2JException
      The main method.
      NORMAL Mode:
      Validates, if the input XML file is passed as an argument.
      if yes, checks whether JSON schema is passes as an argument as well.
      if yes, invokes the XMLToJSONConverter.convertToJson(File, File) method.
      otherwise, invokes the XMLToJSONConverter.convertToJson(File) method.
      Additionally, checks if output JSON file path is passed as an argument.
      if yes, writes the converted JSON to the file.
      otherwise, prints the converted JSON in the console. otherwise, prints the usage and exits.

      Usage: java -DInputXml=PATH_OF_INPUT_XML_FILE -DSchemaJson=PATH_OF_SCHEMA_JSON_FILE -DOutputJson=PATH_OF_OUTPUT_JSON_FILE -jar XML2JSON-0.0.1-SNAPSHOT-jar-with-dependencies.jar

      TEST Mode:
      In case of validation failure, this will throw X2JException instead of stopping the application with an error message.
      Parameters:
      args - the command-line arguments
      Throws:
      X2JException - X2JException
    • setMode

      public static void setMode(X2JExecMode mode)
      Sets the execution mode for the X2J application (X2JExecMode).
      Parameters:
      mode - the new execution mode