GithubHelp home page GithubHelp logo

rogersmarin / avro-schema-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nokia/avro-schema-generator

0.0 1.0 0.0 132 KB

Tool which generates Avro schemas and Java bindings from XML schemas.

License: Apache License 2.0

Java 100.00%

avro-schema-generator's Introduction

What is it?

The schema generator works alongside the JAXB binding compiler to produce Avro bindings which are very similar to the JAXB classes. The process is wrapped in a Maven plugin, which allows for manual or automatic execution of the process. The plugin completes in one step the generation of JAXB classes, Avro schemas, and Avro classes.

For more information about the projet, read the writeup on InfoQ:
http://www.infoq.com/articles/AVROSchemaJAXB

How does it work?

The first part of the process utilizes XJC, the JAXB Binding Compiler, to produce a Java code model from a series of xsd schema files. After this is finished, an XJC plugin runs which inspects the classes to be generated and produces parallel Avro schemas in JSON format. Then the classes and schemas are written out. Finally, the plugin calls the Java schema compiler provided by the Avro project to produce a new set of Java classes for serialization to and from Avro.

Where to get it?

Currently the plugin is not available from maven central, so you will have to download the source and install it to your local Maven repository.

How to run it.

The schema generator is wrapped into a Maven plugin, which can be executed manually or as part of a build process. The schemagen-plugin component provides a plugin with one goal, "generate". There is no default phase to which the goal is bound, so it will never be executed automatically without first specifying the phase when it should run. For example, the 'validate' or 'generate-sources' phase is a good place to put such activities, as they run prior to the compile phase.

Your Maven project would include a plugin declaration similar to this:

<plugin>
    <groupId>com.nokia.util.avro</groupId>
    <artifactId>schemagen-plugin</artifactId>
    <version>0.3</version>
    <configuration>
        <outputDirectory>..\sources</outputDirectory>
        <packageName>my.generated</packageName>
        <bindingFiles>
            <file>resources/binding1.xsd</file>
        </bindingFiles>
        <schemaFiles>
            <schema>resources/schema1.xsd</schema>
        </schemaFiles>
    </configuration>
</plugin>

Currently you must provide all schema files you wish to be considered in the bindings and schemas lists. The plugin's exposed name is "schemagen". So now from the command line you can navigate to your POM file and execute the following command:

mvn schemagen:generate

This will invoke the entire workflow on your input data. The artifacts produced by the process are:

  • JAXB generated Java sources
  • Avro schema files (JSON)
  • Avro generated Java sources

You can then use the Java files needed. To have the source files compiled automatically, you will want to either have them created in folder which is part of your Maven project's source directory, or explicitly add an include for the generated directory using the maven-compiler plugin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.