Setup environment for Deep Learning with Deeplearning4j in IntelliJ IDEA

In this tutorial, we shall see how to setup environment for Deep Learning with Deeplearning4j and import the dl4j-examples project from Git into IntelliJ IDEA. The aim is simple: install the required Java development tools, clone the Deeplearning4j examples repository, build it with Maven, and open it as a Maven project in IntelliJ IDEA.

Deeplearning4j, often written as DL4J, is a deep learning framework for the Java Virtual Machine. It is useful when you want to build or run neural network examples using Java and the JVM ecosystem instead of switching completely to Python.

Following are the steps :

  1. Install Java JDK.
  2. Install Apache Maven.
  3. Download IntelliJ IDEA Community Edition.
  4. Install Git.
  5. Start hands-on with dl4j-examples:
    – Clone the Git project “dl4j-examples”.
    – Build the project using Maven.
    – Import the built project to IntelliJ IDEA as a Maven project.

Skip any of the above steps if you have already installed the tool. Also, it is recommended to use supported and recent versions of Java, Maven, Git, and IntelliJ IDEA. If a DL4J example fails because of a version mismatch, check the pom.xml file in the cloned project and use the Java version expected by that project.

Deeplearning4j setup prerequisites for Java deep learning

Before cloning dl4j-examples, make sure the following tools are available from your terminal or command prompt.

ToolWhy it is needed for Deeplearning4j setupVerification command
Java JDKCompiles and runs Java-based DL4J examples.java -version and javac -version
Apache MavenDownloads DL4J dependencies and builds the example project.mvn --version
GitClones the official examples repository.git --version
IntelliJ IDEAOpens the Maven project and runs Java examples from the IDE.Open IntelliJ IDEA and check Project SDK settings.

For reference, the official Deeplearning4j quick-start material is available at https://deeplearning4j.konduit.ai/deeplearning4j/tutorials/quick-start. Use it along with this step-by-step setup guide when you want to compare dependency or version details.

Install Java JDK for Deeplearning4j examples

A step-by-step guide to install java.

Deeplearning4j examples are Java projects, so install a JDK, not only a JRE. The JDK includes the Java compiler required by Maven. After installation, verify Java from a terminal.

</>
Copy
java -version
javac -version

If javac is not recognized, the JDK path is not configured correctly. Set JAVA_HOME to the JDK installation directory and add the JDK bin directory to the system path.

Install Apache Maven for Deeplearning4j dependency management

Step 1 : Download the latest version of Maven at https://maven.apache.org/download.cgi

Step 2 : Install Maven following the instructions at https://maven.apache.org/install.html

Step 3 : Verify if maven is installed using the command

mvn –version

The result would be as shown in the below screenshot :

check maven installation - setup environment for Deep learning with Deeplearning4j - Machine Learning Tutorials - www.tutorialkart.com
Check Maven installation using the command “mvn –version”

In a correct Maven setup, the output should show the Maven version, Java version, Java home, and operating system details. If the command fails, check whether the Maven bin directory is added to the path.

Download IntelliJ IDEA Community Edition for DL4J Java projects

  1. Download the latest version of IntelliJ IDEA from https://www.jetbrains.com/idea/download/
  2. Extract the downloaded package and go into the folder where bin, lib, plugin, etc., folders are present. An installation guide, “Install-Linux-tar.txt” (for Linux installation), is present in the location. [A similar name would be present for other Operating Systems].
  3. Follow the instructions present in the setup guide.

IntelliJ IDEA Community Edition is sufficient for importing and running Maven-based Java examples. During import, select the installed JDK as the Project SDK. If IntelliJ shows Maven dependency errors, refresh the Maven project after the import is complete.

Install Git to clone the dl4j-examples repository

Instructions for installing Git are available at https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

After installing Git, verify it using the following command.

</>
Copy
git --version

Clone and build dl4j-examples for Deeplearning4j hands-on practice

Clone dl4j-examples from GitHub

Create a new directory for working with DL4J projects. Say “dl4j-workspace”. And execute the following git command to download the dl4j-examples from the git repository.

$ git clone https://github.com/deeplearning4j/dl4j-examples.git

Following screenshot shows download in progress for dl4j-examples :

Clone dl4j-examples from Git - setup environment for Deep learning with Deeplearning4j - Machine Learning Tutorials - www.tutorialkart.com
Clone dl4j-examples from Git

You can also keep the commands together as shown below when you are starting from a terminal.

</>
Copy
mkdir dl4j-workspace
cd dl4j-workspace
git clone https://github.com/deeplearning4j/dl4j-examples.git
cd dl4j-examples

Build dl4j-examples with Maven clean install

Once the download is completed, go to the folder dl4j-examples and build the project using the following command

$ mvn clean install

Note : Make sure the JAVA_HOME path variable is pointing to the JDK installed in your machine.

When the command “mvn clean install” is run, the result is as shown in the below screenshot :

mvn clean install of dl4j-examples - setup environment for Deep learning with Deeplearning4j - Machine Learning Tutorials - www.tutorialkart.com
mvn clean install

It takes some time for Maven to download all the artifacts mentioned in the pom file and build the project.

Note : Some older examples or visualization modules may require JavaFX. In case JavaFX is missing, you may get a compile error. On Ubuntu-based systems, you can try installing OpenJFX by executing the following command and then run “mvn clean install” again.

sudo apt-get install openjfx

Once the “mvn clean install” command is successful, you should see the BUILD SUCCESS as seen in the below screenshot :

dl4j-examples BUILD SUCCESS - setup environment for Deep learning with Deeplearning4j - Machine Learning Tutorials - www.tutorialkart.com
dl4j-examples BUILD SUCCESS

If you only want to check whether Maven can resolve dependencies and compile the project, use the full build first. After that, individual examples can usually be run from IntelliJ IDEA from their Java class files.

Import dl4j-examples into IntelliJ IDEA as a Maven project

Open IntelliJ IDEA before importing the Deeplearning4j project

Start IntelliJ IDEA.

Start intelliJ IDEA
  • Click on Import Project

Import Project

In recent IntelliJ IDEA versions, the same action may appear as Open instead of Import Project. Select the cloned dl4j-examples folder and let IntelliJ detect it as a Maven project.

Choose the project folder. Click OK.

Choose Project Folder

Import Project as Maven model. Click Next.

Import project as Maven

Project configuration. Keep defaults and Click on Next.

Project Configuration

Select Profile – OpenJFX. Click Next.

OpenJFX Profile

Select the Maven projects in the project folder. Click Next.

Select Maven Projects from the project folder

Select project SDK. Click Next.

Select SDK for Project

The final step, give a name to the project. Click Finish.

Give Project Name

It takes some time for IntelliJ to index the resources in the project. And the project structure would look something link in the following screenshot.

dl4j examples Project Structure

The project “dl4j-examples” is successfully setup.

Run a Deeplearning4j neural network example in IntelliJ IDEA

After the Maven import finishes, expand the source folders in IntelliJ IDEA and open a Java example class. Right-click the class that contains the main method and select Run. IntelliJ will use the selected JDK and Maven dependencies to execute the example.

DeepLearning4j examples may include different kinds of neural network tasks, such as feed-forward networks, convolutional networks, recurrent networks, embeddings, and model training utilities. Start with a small beginner example before trying a large dataset or GPU-based setup.

Common Deeplearning4j setup errors and fixes

ProblemLikely causeFix
mvn command not foundMaven is not installed or Maven bin is not in PATH.Install Maven and add its bin directory to the system path.
javac command not foundOnly JRE is installed, or JDK path is not configured.Install JDK and set JAVA_HOME correctly.
Maven dependency download is slowFirst build downloads many dependencies.Wait for the first build to complete; later builds are faster because Maven caches dependencies.
JavaFX compile errorJavaFX modules are missing for examples that need them.Install OpenJFX or use the required JavaFX profile for that example.
Project SDK not selected in IntelliJIntelliJ has not been pointed to the installed JDK.Open Project Structure and choose the correct JDK as Project SDK.

QA checklist for Deeplearning4j environment setup

  • Java JDK is installed and both java -version and javac -version work.
  • JAVA_HOME points to the JDK directory, not a standalone JRE directory.
  • Apache Maven is installed and mvn --version shows the expected Java home.
  • Git is installed and the dl4j-examples repository is cloned successfully.
  • mvn clean install completes with BUILD SUCCESS before importing or running examples.
  • IntelliJ IDEA imports the project as Maven and uses the correct Project SDK.

FAQs on setting up Deeplearning4j for Java deep learning

Is DL4J a deep learning framework?

Yes. DL4J, or Deeplearning4j, is a deep learning framework for the Java Virtual Machine. It lets Java developers work with neural network examples and deep learning workflows using Java-based tooling.

How do I create a deep learning neural network in Java with Deeplearning4j?

The usual starting point is to set up Java JDK, Maven, Git, and an IDE such as IntelliJ IDEA, then clone dl4j-examples. Study and run a beginner example first, then modify the model configuration, input data, training settings, and evaluation code.

What deep learning algorithms can we implement using Deeplearning4j?

With Deeplearning4j, you can work with common neural network approaches such as multilayer feed-forward networks, convolutional neural networks, recurrent networks, LSTM-style sequence models, embeddings, and related deep learning examples. The exact available examples depend on the version and modules present in the project you clone.

Do I need IntelliJ IDEA to use Deeplearning4j?

No. IntelliJ IDEA is convenient, but Deeplearning4j Maven projects can also be built from the terminal using Maven. An IDE helps when browsing code, resolving imports, running examples, and debugging Java classes.

Why does Maven take time during the first Deeplearning4j build?

The first Maven build downloads all required dependencies declared in the project pom.xml. This can take time depending on the project size and internet connection. After the first successful build, many dependencies are stored in the local Maven cache.

Conclusion on Deeplearning4j environment setup

In this Deep Learning tutorial, we have seen how to setup environment for Deep learning with Deeplearning4j and import the Git project “dl4j-examples” to IntelliJ IDEA. Once the build succeeds and the Maven project opens correctly, you can start running beginner DL4J examples and then move to more specific neural network use cases.