Setup Project
Web3J allows you to integrate your Java blockchain application into an existing standard Java application. It does this by wrapping your blockchain application in a standard application wrapper. This article walks you through this process. We recommend that you follow this article through by using the supplied Counter contract. Once you are comfortable with the process, you can attempt to wrap your custom Java blockchain application.
Prerequisites
First up, make sure that you have the following prerequisites:
- Java 10 or above
Generate the Sample Contract
We will be using the following contract in this tutorial. It is a simple Counter contract that increases or decreses the value of the count variable by an integer.
You can either compile the above contract yourself, or you can use the pre-compiled jar and abi files we have generated for you:
Once you have your .jar and .abi files, move them to a convenient location.
Generate the Contract Wrapper
In order for a standard Java application to interact with your Java contract, you need to wrap it within the Web3J wrapper. While the process is the same for any Java contract, the output is different. A wrapper for one Java contract will not work for any other Java contract.
- Download the Aion Web3J package from GitHub: 
- Move into the new folder: 
- Generate the binary distribution using Gradlew: - You might see a warning about - Deprecated Gradle features. You can safely ignore this for now. It will be fixed in a future release.
- Move into the distributions folder: 
- Extract the - web3j-aion-0.1.0-SNAPSHOT.zipfile:
- Move into - binfolder:
- Web3J now needs the - jarand- abifiles from your blockchain application. Copy your- .jarand- .abifiles into this folder:
- Generate your Aion contract wrapper: - The - -o ~/Desktopdirectory in this command is the location where you wrapper will be saved. To keep thing simple we’ve told Gradle to save it to the desktop. You can find your- Counter.javawrapper in the- ~/Desktop/aion/folder.- For future reference, the following arguments are available: - Flag - Required - Description - -a,- --abiFile- true- ABI file in AVM format with a contract definition. - -b,- --binFile- false- BIN or JAR file with the contract compiled code in order to generate deploy methods. - -o,- --outputDir- true- Destination base directory. - -p,- --package- true- Base package name. - -t,- --targetVm- false- Target Aion virtual machine (AVM by default). 
If you used the example counter contract, your Counter.java wrapper should look something like this:
Generate the Library
The library produced by this module must be present in your classpath when running an Aion Java contract wrapper. The Encoding and decoding do not work without it.
- Move back into the - web3j-aion-masterfolder you downloaded from GitHub:
- Create SOMETHING: 
- Move into the newly created - libsfolder:
- You should be able to see a file called - web3j-aion-avm-0.1.0-SNAPSHOT-all.jar.
You can use it by simply adding it to your classpath.
Make sure you put the contract wrapper and the library jar in your project. Check out this project example for reference.
You’re Java blockchain application is now wrapped within the Web3J wrapper. You should now be able to integrate it into other existing Java applications so that they can interact with the Aion blockchain.