• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

web3j/web3j-maven-plugin: web3j Maven plugin

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

web3j/web3j-maven-plugin

开源软件地址(OpenSource Url):

https://github.com/web3j/web3j-maven-plugin

开源编程语言(OpenSource Language):

Java 92.6%

开源软件介绍(OpenSource Introduction):

web3j-maven-plugin

Build Status codecov.io License

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.

<build>
    <plugins>
        <plugin>
            <groupId>org.web3j</groupId>
            <artifactId>web3j-maven-plugin</artifactId>
            <version>4.9.4</version>
            <configuration>
                <soliditySourceFiles/>
            </configuration>
        </plugin>
    </plugins>
</build>

to run the plugin execute the goal generate-sources

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
<packageName/> valid java package name org.web3j.model
<outputDirectory><java/></outputDirectory> relative or absolute path of the generated for 'Java files value in <sourceDestination/>
<outputDirectory><bin/></outputDirectory> relative or absolute path of the generated for 'Bin' files value in <sourceDestination/>
<outputDirectory><abi/></outputDirectory> relative or absolute path of the generated for 'ABI' files value in <sourceDestination/>
<sourceDestination/> relative or absolute path of the generated files (java, bin, abi) src/main/java
<outputFormat/> generate Java Classes(java), ABI(abi) and/or BIN (bin) Files (comma separated) java
<nativeJavaType/> Creates Java Native Types (instead of Solidity Types) true
<outputJavaParentContractClassName/> Sets custom(? extends org.web3j.tx.Contract) class as a parent for java generated code org.web3j.tx.Contract
<soliditySourceFiles> Standard maven fileset <soliditySourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>**/*.sol</include>
</includes>
</soliditySourceFiles>
<abiSourceFiles> Standard maven fileset <abiSourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>**/*.json</include>
</includes>
</abiSourceFiles>
<contract> Filter (<include> or <exclude>) contracts based on the name. <contract>
<includes>
<include>greeter</include>
</includes>
<excludes>
<exclude>mortal</exclude>
<excludes>
</contracts>
<pathPrefixes> A list (<pathPrefixe>) 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 <plugin> - configuration into the pom.xml file:

<plugin>
    <groupId>org.web3j</groupId>
    <artifactId>web3j-maven-plugin</artifactId>
    <version>4.8.1</version>
    <configuration>
        <packageName>com.zuehlke.blockchain.model</packageName>
        <sourceDestination>src/main/java/generated</sourceDestination>
        <nativeJavaType>true</nativeJavaType>
        <outputFormat>java,bin</outputFormat>
        <soliditySourceFiles>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.sol</include>
            </includes>
        </soliditySourceFiles>
        <abiSourceFiles>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.json</include>
            </includes>
        </abiSourceFiles>
        <outputDirectory>
            <java>src/java/generated</java>
            <bin>src/bin/generated</bin>
            <abi>src/abi/generated</abi>
        </outputDirectory>
        <contract>
            <includes>
                <include>greeter</include>
            </includes>
            <excludes>
                <exclude>mortal</exclude>
            </excludes>
        </contract>
        <pathPrefixes>
            <pathPrefix>dep=../dependencies</pathPrefix>
        </pathPrefixes>
    </configuration>
</plugin>

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 in the official web3j documentation.

For a multi module project configuration see following post from @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.

Changelog

4.8.1

  • Update web3j core version to 4.8.1

4.6.5

  • Replace SolC with Sokt (thx to @josh-richardson & @AlexandrouR)

4.5.11

  • Update web3j core version to 4.5.11
  • Update solcj version to 0.5.7

Changelog

4.2.0

  • Update web3j core version to 4.2.0

4.1.0

  • Update web3j core version to 4.1.0
  • Revert Java Update

4.0.3

  • Bringing all web3j-related projects up to the same build number to reduce confusion

0.3.7

  • Update solcj version to 0.4.25
  • Update web3j core version to 3.5.0
  • Destination Directory for ABI, BIN and Java can be different

0.3.5

  • Generate and Store ABI & BIN Files
  • Update to 3.5.0 web3j core version

0.3.1

  • Update to newest solcj version. Support for Solidity Version 0.4.24
  • Update to 3.4.0 web3j core version

0.3.0

  • Support of imported Files import './other.sol';

0.2.0

  • Update Core Version

0.1.4

  • Update Core Version

0.1.3

  • Update Core Version
  • Support Java Native Type creation

0.1.2

  • Better Contract Handling

0.1.1

  • Initial Release



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Coveros/helloworld: A Java Hello World application using Maven发布时间:2022-08-16
下一篇:
amuthansakthivel/MavenTestNG发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap