IntelliJ IDEA Configuration for java-tron¶
To simplify the Java development process and improve efficiency, selecting and configuring an Integrated Development Environment (IDE) is a crucial first step. This guide uses IntelliJ IDEA as an example to explain how to set up and configure the java-tron development environment.
java-tron nodes support deployment on Linux
or MacOS
operating systems. The JDK version requirements are as follows:
- General Requirement: Oracle JDK 1.8
- For
v4.8.1
and later: Support is also provided for JDK 17 on the ARM architecture
Prerequisites¶
Before you begin, please ensure your development environment meets the following requirements:
- Operating System:
Linux
orMacOS
- Oracle JDK 1.8 is installed
git
is installed- IntelliJ IDEA is installed
Configuring the IntelliJ IDEA Environment¶
Step 1: Install the Lombok Plugin¶
Lombok simplifies Java code through annotations and is an essential plugin for java-tron development.
- Open IntelliJ IDEA and navigate to
Preferences
->Plugins
. - In the Marketplace tab, search for
Lombok
. - Click "Install" and restart the IDE when prompted.
Step 2: Enable Annotation Processing¶
To ensure Lombok's annotations work correctly, you must enable the annotation processor.
- Navigate to
Preferences
->Build, Execution, Deployment
->Compiler
->Annotation Processors
. - Select the
Enable annotation processing
checkbox. - Click "Apply" to save the settings.
Step 3: Verify and Unify the JDK Version¶
To ensure the project compiles and runs correctly, you must set the JDK version to Oracle JDK 1.8 in two key locations within IntelliJ IDEA.
1. Configure Project SDK¶
This is the core JDK used for compiling the project's source code and performing syntax analysis.
- Navigate to
File
->Project Structure
->, and select "Project" from the left panel. - In the
Project SDK
dropdown menu, confirm that version1.8
is selected.
2. Configure Gradle JVM¶
This is the JDK used to execute Gradle build tasks (e.g., build, clean).
- Navigate to
Preferences
->Build, Execution, Deployment
->Build Tools
->Gradle
. - In the Gradle JVM dropdown menu on the right, ensure that the selected version is also
1.8
, consistent with the Project SDK.
Important Note: The Project SDK and Gradle JVM settings must match and both be set to Oracle JDK 1.8. Otherwise, you may encounter unexpected errors during the build process.
Getting and Compiling the Source Code¶
Step 1: Clone the Source Code¶
Clone the java-tron source code to your local machine and switch to the develop
branch.
git clone https://github.com/tronprotocol/java-tron.git
cd java-tron
git checkout -t origin/develop
Step 2: Compile java-tron¶
You can compile the project in two ways:
-
Compile using the terminal:
In the root directory of the
java-tron
project, execute the following Gradle command:To speed up the compilation process by skipping unit tests, you can use the# Perform a full build, including all test cases ./gradlew clean build
-x test
argument:* Compile using the IntelliJ IDEA UI:# Compile while skipping tests ./gradlew clean build -x test
Open the
java-tron
project in IntelliJ IDEA, then clickBuild
->Build Project
in the top menu bar to compile the entire project.
Configuring Code Style Checks¶
java-tron adheres to the Google checkstyle
code standard. By configuring the Checkstyle
plugin in IDEA, you can check your code style in real-time to ensure the quality of your commits.
Step 1: Install the Checkstyle Plugin¶
- In IDEA, navigate to
Preferences
->Plugins
。 - In the Marketplace, search for and install the
Checkstyle
plugin.
Step 2: Configure Checkstyle Rules¶
- First, locate the code style configuration file. You can use the local
config/checkstyle/checkStyleAll.xml
file within the project, or download it from the official GitHub Repository. - In IDEA, navigate to
Preferences
->Tools
->Checkstyle
to open the configuration panel. - In the
Configuration File
panel, click the+
icon to add a new configuration. - In the dialog that appears, set the
Description
totron-checkstyle
and select thecheckStyleAll.xml
file you just obtained. - Select the checkbox for the newly added
tron-checkstyle
rule and click "Apply" and "OK".
Once configured, you can use the Checkstyle
plugin to check your code style. It supports various scopes, allowing you to analyze the entire project, a single module, or the file you are currently editing. The most common operation is to check the current file:
- Right-click in the code editor.
- Select "Check Current File".
If any code style issues are detected, Checkstyle
will list them in a window at the bottom. Before committing your code, correct all reported issues according to the prompts to maintain codebase consistency.
Running and Debugging¶
Step 1: Create a Working Directory¶
Before running java-tron, you need to create a working directory to store the database and log files generated by the node at runtime.
mkdir /Users/javatrondeploy
Important Note: java-tron will look for the
config.conf
file in this directory. Before starting the node, ensure you have placed the correct configuration file in this directory.
Step 2: Configure Run/Debug Options¶
Next, create a new run configuration in IntelliJ IDEA to define how it launches the java-tron application.
- In the top-right corner of IDEA, click
Add Configuration...
. - Click
+
->Application
to create a new run configuration. - Find and set the following options in order:
- Name: Give the configuration a name, e.g.,
Fullnode
. - JDK: Ensure you select
java 8 1.8
. - Main Class: Set to
org.tron.program.FullNode
. - Program Arguments: Enter the node startup arguments. For example, use
-c config.conf
to specify the configuration file. - Working Directory: Set this to the directory you created in Step 1, e.g.,
/Users/javatrondeploy
。
- Name: Give the configuration a name, e.g.,
- Click “Apply” to save the configuration.
Step 3: Start the Node¶
Now you can start the java-tron node from within IDEA:
- Run the node: Click
Run
->Run 'FullNode'
in the top menu bar. - Debug the node: Set breakpoints in your code, then click
Run
->Debug 'FullNode'
. The program will pause at the breakpoints, which allows you to perform step-by-step debugging.
After the node starts, relevant log files will be written to the Working directory
you configured.