# web3j-maven-plugin **Repository Path**: hyperledger/web3j-maven-plugin ## Basic Information - **Project Name**: web3j-maven-plugin - **Description**: web3j Maven plugin - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-04-11 - **Last Updated**: 2024-11-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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.