Build the Ontology JAVA SDK development environment in IDEA under Ubuntu 14.04

Reminder: Ontology needs to be deployed on a single machine. For details, please refer to Ontology Development Environment Construction, Deployment and Testing under Ubuntu 14.04

Install Java

  • Download Java

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Open the above link, Enter image description, to download the specific Java8 version. The author chose jdk-8u172-linux-x64.tar.gz.

  • Configure Java environment variables

Extract jdk-8u172-linux-x64.tar.gz to the specified directory

blockchain@ThinkPad-T460:~$ tar -zxvf ~/Downloads/jdk-8u172-linux-x64.tar.gz -C ~

Edit the .bashrc file in your home directory

blockchain@ThinkPad-T460:~$ vim ~/.bashrc 

add at the end of the file

export JAVA_HOME=$HOME/jdk1.8.0_172
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=$PATH:${JAVA_HOME}/bin

Make the configuration take effect immediately

blockchain@ThinkPad-T460:~$ source ~/.bashrc

View Java version

blockchain@ThinkPad-T460:~$ java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

Install Maven

  • Download Maven

http://www-eu.apache.org/dist/maven/maven-3/

Open the above link, Enter image description, enter the corresponding directory, and download the specific Maven version. The author chose apache-maven-3.3.9-bin.tar.gz.

  • Configure Maven environment variables

Extract apache-maven-3.3.9-bin.tar.gz to the specified directory

blockchain@ThinkPad-T460:~$ tar -zxvf ~/Downloads/apache-maven-3.3.9-bin.tar.gz -C ~

Edit the .bashrc file in your home directory

blockchain@ThinkPad-T460:~$ vim ~/.bashrc

add at the end of the file

export MAVEN_HOME=$HOME/apache-maven-3.3.9
export PATH=$PATH:${MAVEN_HOME}/bin

Make the configuration take effect immediately

blockchain@ThinkPad-T460:~$ source ~/.bashrc

View Maven version

blockchain@ThinkPad-T460:~$ mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /home/blockchain/apache-maven-3.3.9
Java version: 1.8.0_172, vendor: Oracle Corporation
Java home: /home/blockchain/jdk1.8.0_172/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-116-generic", arch: "amd64", family: "unix"
  • Configure Maven mirroring

Edit MAVEN_HOME, settings.xml under the conf folder

blockchain@ThinkPad-T460:~$ vim $MAVEN_HOME/conf/settings.xml 

Find the mirrors mirror node and add mirror nodes as follows:

  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

Build Ontology JAVA SDK development environment

  • Download ontology-java-sdk
blockchain@ThinkPad-T460:~/GitClone$ git clone https://github.com/ontio/ontology-java-sdk
Cloning into 'ontology-java-sdk'...
remote: Counting objects: 2322, done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 2322 (delta 19), reused 47 (delta 12), pack-reused 2240
Receiving objects: 100% (2322/2322), 592.08 KiB | 302.00 KiB/s, done.
Resolving deltas: 100% (1264/1264), done.
Checking connectivity... done.
blockchain@ThinkPad-T460:~/GitClone$ ls -lt
total 4
drwxrwxr-x 5 blockchain blockchain 4096  4月 26 16:56 ontology-java-sdk

ontology-java-sdk is a Maven project.

  • Download IDEA Community Edition

https://www.jetbrains.com/idea/download/previous.html , click the linkEnter image description

The author chose ideaIC-2017.3.5-no-jdk.tar.gz. Unzip the compressed file

blockchain@ThinkPad-T460:~$ tar -zxvf ~/Downloads/ideaIC-2017.3.5-no-jdk.tar.gz -C ~

start IDEA

blockchain@ThinkPad-T460:~$ idea-IC-173.4674.33/bin/idea.sh 

Enter the following interface,

Enter image description

Click Open to open the ontology-java-sdk project downloaded above.

Enter image description

Click OK. At this point, it will enter the project. Click File --> Settings in the upper left corner

Enter image description

In the image below, select the Maven path installed in the previous step and confirm.

Enter image description

Right-click pom.xml, click Reimport in the Maven options, then Maven will pull the dependent Jar package.

Enter image description

So far, Ontology's Java SDK development environment is completed. Below, let's run a few of these examples.

Run the AccountDemo instance under the demo package.

Enter image description

Run the demo instance under the demo package.

Enter image description

Run the ECIESDemo instance under the demo package.

Enter image description

Run the MakeTxDemo instance under the demo package.

Enter image description

Run the OntAssetDemo instance under the demo package.

Enter image description

Run the RecordTxDemo instance under the demo package.

Enter image description

Interested readers can run all the examples, and there may be unexpected gains~~

Original link: Please indicate the source for reprinting, thank you!

For more information, please follow the WeChat public accountEnter image description

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325055329&siteId=291194637