
- Flat Buffers - Home
- Flat Buffers - Introduction
- Flat Buffers - Environment Setup
- Flat Buffers - Schema
- Flat Buffers - Constructs
- Flat Buffers - table
- Flat Buffers - string
- Flat Buffers - Numbers
- Flat Buffers - Boolean
- Flat Buffers - Enum
- Flat Buffers - Vector
- Flat Buffers - Struct
- Flat Buffers - Union
- Flat Buffers - Nested Table
- Flat Buffers - Default Values
- Flat Buffers - JSON to Binary
- Flat Buffers - Binary to JSON
- Flat Buffers - Mutatable Buffers
- Flat Buffers - Backward Compatability
- Flat Buffers - Language Independence
- Flat Buffers Useful Resources
- Flat Buffers - Quick Guide
- Flat Buffers - Useful Resources
- Flat Buffers - Discussion
Flat Buffers - Environment Setup
Install Java
We're using Java Based examples to demonstrate Flat Buffers, this section guides you on how to download and set up Java on your machine. Please follow the following steps to set up the environment.
Java SE is freely available from the link Download Java. So you download a version based on your operating system.
Follow the instructions to download java and run the .exe to install Java on your machine. Once you installed Java on your machine, you would need to set environment variables to point to correct installation directories:
Setting up the path for windows 2000/XP:
Assuming you have installed Java in c:\Program Files\java\jdk directory:
Right-click on 'My Computer' and select 'Properties'.
Click on the 'Environment variables' button under the 'Advanced' tab.
Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.
Setting up the path for windows 95/98/ME:
Assuming you have installed Java in c:\Program Files\java\jdk directory:
Edit the 'C:\autoexec.bat' file and add the following line at the end:
'SET PATH=%PATH%;C:\Program Files\java\jdk\bin'
Setting up the path for Linux, UNIX, Solaris, FreeBSD:
Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation if you have trouble doing this.
Example, if you use bash as your shell, then you would add the following line to the end of your '.bashrc: export PATH=/path/to/java:$PATH'
Popular Java Editors:
To write your Java programs, you will need a text editor. There are even more sophisticated IDEs available in the market. But for now, you can consider one of the following:
Notepad: On Windows machine you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad.
Netbeans:is a Java IDE that is open-source and free which can be downloaded from https://www.netbeans.org/index.html.
Eclipse: is also a Java IDE developed by the eclipse open-source community and can be downloaded from https://www.eclipse.org/.
Install Maven
Maven is project management and build tool. We're using Maven to build our examples. This section guides on how to install and set up maven on your machine. Please follow the following steps to set up the environment.
Maven is freely available from the link Download Maven Installer. So you download a version based on your operating system.
Follow the instructions to download maven zip the extract Maven on your machine. Once you extract Maven files on your machine, you would need to set environment variables to point to correct installation directories. You can follow the instructions at Maven - Environment Setup Chapter.
Install FlatBuffers Library
Once Java and Maven environment is ready. We can use flatbuffers dependency in pom.xml to use it in our java based projects as shown in snippet below −
<dependency> <groupId>com.google.flatbuffers</groupId> <artifactId>flatbuffers-java</artifactId> <version>25.2.10</version> </dependency>
Build Maven Project
Now when you compile the maven project, maven will automatically download the flatbuffers library, build the code and run accordingly.
mvn clean install
Install FlatBuffer Compiler
Let us install the "flatc" binary which we will use to autogenerate the code from Flat Buffers schema. The binaries can be found at "https://github.com/google/flatbuffers/releases".
Choose the correct binary based on the OS. We will install flat buffers compiler binary on Windows but the steps are not very different for Linux.
We've downloaded https://github.com/google/flatbuffers/releases/download/v25.2.10/Windows.flatc.binary.zip
Verify Flat Buffers Compiler Setup
Once installed, ensure that you are able to access it via command line by adding its path in PATH environment variable −
flatc --version flatc version 25.2.10
It confirms that Flatc is correctly installed.