Welcome to Java SDK for Hyperledger project. This is a summary of steps required to get you started with building and using the Java SDK. Please note that this is not the API documentation or a tutorial for the SDK, this will only help you familiarize to get started with the SDK if you are new in this domain.
To build this project, following dependencies must be met
- JDK 1.8 or above
- Apache Maven
Once your JAVA_HOME points to your installation of JDK 1.8 (or above) and JAVA_HOME/bin and Apache maven are in your PATH, issue the following command to build the jar file:
mvn install
or
mvn install -DskipTests
if you don't want to run the unit tests
To run the unit tests, please use mvn test
or mvn install
which will run the unit tests and build the jar file. You must be running a local instance of membersrvcs and a peer to be able to run the unit tests. Please follow the instructions here to setup the development environment.
To use the SDK in your code, simply add the generated JAR file in your classpath.
Once the JAR file is in your classpath, create a chain instance to interact with the network.
Chain testChain = new Chain("chain1");
Add the membership service:
testChain.setMemberServicesUrl("grpc://localhost:7054", null);
Set a keyValueStore:
testChain.setKeyValStore(new FileKeyValStore(System.getProperty("user.home")+"/test.properties"));
Add a peer to the chain:
testChain.addPeer("grpc://localhost:7051", null);
Get a member:
Member registrar = testChain.getMember("admin");
Enroll a member:
Member member = testChain.enroll("user", "secret");
SDK depends on few third party libraries that must be included in your classpath when using the JAR file. To get a list of dependencies, refer to pom.xml file or run
mvn dependency:tree
or mvn dependency:list
.
Alternatively, mvn dependency:analyze-report
will produce a report in HTML format in target directory listing all the dependencies in a more readable format.