Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hyperledger-web3j/web3j-maven-plugin
web3j Maven plugin
https://github.com/hyperledger-web3j/web3j-maven-plugin
blockchain ethereum java maven-plugin solidity solidity-contracts web3j
Last synced: 1 day ago
JSON representation
web3j Maven plugin
- Host: GitHub
- URL: https://github.com/hyperledger-web3j/web3j-maven-plugin
- Owner: hyperledger-web3j
- License: apache-2.0
- Created: 2017-05-18T23:49:21.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-08-16T14:52:10.000Z (3 months ago)
- Last Synced: 2024-11-12T20:16:29.809Z (1 day ago)
- Topics: blockchain, ethereum, java, maven-plugin, solidity, solidity-contracts, web3j
- Language: Java
- Size: 298 KB
- Stars: 117
- Watchers: 13
- Forks: 82
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# web3j-maven-plugin
[![build status](https://github.com/web3j/web3j-maven-plugin/actions/workflows/maven.yml/badge.svg)](https://github.com/web3j/web3j-maven-plugin/actions/workflows/maven.yml)
[![codecov](https://codecov.io/gh/web3j/web3j-maven-plugin/branch/master/graph/badge.svg?token=Ar7tgwmUEz)](https://codecov.io/gh/web3j/web3j-maven-plugin)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)web3j maven plugin is used to create java classes based on the solidity contract files.
## Usage
The base configuration for the plugin will take the solidity files from `src/main/resources` and generates
the java classes into the folder `src/main/java`.```xml
org.web3j
web3j-maven-plugin
4.12.1
```
to run the plugin execute the goal `generate-sources`
```bash
mvn web3j:generate-sources
```## Configuration
The are several variable to select the solidity source files, define a source destination path or change the package name.| Name | Format | Default value |
| -----------------------|----------------------------------------------------------------------------------------| --------------------------------|
| `` | valid java package name | `org.web3j.model` |
| `` | relative or absolute path of the generated for 'Java files | value in `` |
| `` | relative or absolute path of the generated for 'Bin' files | value in `` |
| `` | relative or absolute path of the generated for 'ABI' files | value in `` |
| `` | relative or absolute path of the generated files (java, bin, abi) | `src/main/java` |
| `` | generate Java Classes(`java`), ABI(`abi`) and/or BIN (`bin`) Files (comma separated) | `java` |
| `` | Creates Java Native Types (instead of Solidity Types) | `true` |
| `` | Sets custom(? extends org.web3j.tx.Contract) class as a parent for java generated code | `org.web3j.tx.Contract` |
| ``| Standard maven [fileset](https://maven.apache.org/shared/file-management/fileset.html) | ``
` src/main/resources`
` `
` **/*.sol`
` `
`` |
| `` | Standard maven [fileset](https://maven.apache.org/shared/file-management/fileset.html) | ``
` src/main/resources`
` `
` **/*.json`
` `
`` |
| `` | Filter (`` or ``) contracts based on the name. | ``
` `
` greeter`
` `
` `
` mortal`
` `
`` |
| `` | A list (``) of replacements of dependency replacements inside Solidity contract. | |Configuration of `outputDirectory` has priority over `sourceDestination`
## Getting Started
Create a standard java maven project. Add following `` - configuration into the `pom.xml` file:
```xml
org.web3j
web3j-maven-plugin
4.11.1
com.zuehlke.blockchain.model
src/main/java/generated
true
java,bin
src/main/resources
**/*.sol
src/main/resources
**/*.json
src/java/generated
src/bin/generated
src/abi/generated
greeter
mortal
dep=../dependencies
```
Add your solidity contract files into the folder `src/main/resources`. Make sure that the solidity files
ends with `.sol`.Start the generating process:
```
> mvn web3j:generate-sources[INFO] --- web3j-maven-plugin:0.1.2:generate-sources (default-cli) @ hotel-showcase ---
[INFO] process 'HotelShowCaseProxy.sol'
[INFO] Built Class for contract 'HotelShowCaseProxy'
[INFO] Built Class for contract 'HotelShowCaseV2'
[INFO] Built Class for contract 'Owned'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.681 s
[INFO] Finished at: 2017-06-13T07:07:04+02:00
[INFO] Final Memory: 14M/187M
[INFO] ------------------------------------------------------------------------Process finished with exit code 0
```You find the generated java classes inside the directory `src/main/java/generated/`.
Next step is to interact with the smart contract. See for that
[deploying and interacting with smart contracts](https://web3j.readthedocs.io/en/latest/smart_contracts.html#deploying-and-interacting-with-smart-contracts)
in the official web3j documentation.For a multi module project configuration see following [post](https://github.com/web3j/web3j-maven-plugin/issues/14)
from [@fcorneli](https://github.com/fcorneli). In short: For pick up the generated java source
files, you need the build-helper-maven-plugin configuration. Also, `${basedir}` prefix is required
within a multi-module project.