---
# System prepended metadata

title: Neo4j Development and Deployment Guideline

---

# Neo4j Development and Deployment Guideline
--- 

[TOC]
## 0. Environment
- OS: Window, Ubuntu, Centos
- IDE: Eclipe [Download](https://www.eclipse.org/downloads/), Intellij [Download](https://www.jetbrains.com/idea/download/)
- Java SDK 11 - [Download](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html)
- Maven 3.8.1 - [Download](https://maven.apache.org/download.cgi), [Setup Guideline](https://linuxize.com/post/how-to-install-apache-maven-on-ubuntu-20-04/)
- Neo4j 4.3.2 Enterprise - [Download](https://neo4j.com/download/)
- Docker, Docker compose - [Download](https://www.docker.com/products/docker-desktop), [Setup Guideline](https://docs.docker.com/engine/install/ubuntu/)



## 1. Settup & Environment

### Setup develop environment
1.1 Setup Environment for system. 
> Select the operating system you want to use


1.2 Install Docker, Docker compose
- Follow step by step in setup guide
- Add permisson for Docker on Ubuntu/linux
```command
sudo groupadd docker
sudo usermod -aG docker $USER
```
- Run Docker with administrator on Windows

3.2 Install Java SDK
4.3 Install Maven
5.4 Install IDE

### Setup environment Neo4j
#### 1. Install Portainer (Docker compose)

1.1 Run commandline 

```command
docker volume create portainer_data
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
```

![](https://i.imgur.com/zvWIftm.png)


1.2 Open browser with url: http://localhost:9000/

1.3 Create new user for portainer system

![](https://i.imgur.com/9TuyKyk.png)

1.4 Conenct portainer to docker environment

![](https://i.imgur.com/JZIEUS5.png)

Select Docker (Manager the local Docker environment)
Click Conenct button

1.5 Portainer Dashboard

![](https://i.imgur.com/lLmMFu5.png)


**Notes:**

> The Portainer will be auto start with docker when the system startup.

#### 2. Setup Neo4j with docker compose

2.1 Add new stack for Neo4j container

- Open dashboard: http://localhost:9000/

- Select Endpoint:
![](https://i.imgur.com/6lCHk1l.png)
Click to local endpoint

- Open Stacks
![](https://i.imgur.com/oZoKAZY.png)

- New stack
Enter name stack: Neo4j Database
Enter script stack:

> docker-compose.yml for 1 instance
```dockerfile=
version: '3'
services:
  neo4j-instance-1:
    image: neo4j:enterprise
    hostname: instance1
    container_name: neo4j-i1
    ports:
      - "7474:7474"
      - "7687:7687"
    volumes:
       - ./db_neo4j_logs_instance_1:/logs
    environment:
      - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes

networks:
  cluster:
    driver: bridge
```


> docker-compose.yml for 3 instances

```dockerfile=

```

- Click deploy the stack
- Open Neo4j Console
http://localhost:7474/browser/http://localhost:7474/browser/
![](https://i.imgur.com/Dc7S7FZ.png)

> Default user: neo4j/neo4j

- Create new password for system account (user neo4j)

![](https://i.imgur.com/X60xkxK.png)

- Neo4j Console dashboard
![](https://i.imgur.com/X06YXFJ.png)


## 2. Development

2.1 Clone repository and build

- Clone repository with ssh or https 

```cmd=
git clone url_reposiroty.git
```

- Build repository

```cmd=
cd repository_folder
mvn clean install
```

2.2 Development guideline

- Dependencies library:

```xml=
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-core</artifactId>
    <version>3.2</version>
    <scope>compile</scope>
</dependency>

<!-- Only add if you're using the Bolt driver -->
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-bolt-driver</artifactId>
    <version>3.2</version>
    <scope>runtime</scope>
</dependency>

<!-- Only add if you're using the HTTP driver -->
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-http-driver</artifactId>
    <version>3.2</version>
    <scope>runtime</scope>
</dependency>

<!-- Only add if you're using the Embedded driver -->
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-embedded-driver</artifactId>
    <version>3.2</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j</artifactId>
    <version>4.1</version>
    <scope>runtime</scope>
</dependency>
```

- Code guide:

> Basic Bolt Driver Configuration
```java=
Configuration configuration = new Configuration.Builder()
        .uri("bolt://neo4j:password@localhost")
        .setConnectionPoolSize(150)
        .build()
```

> Permanent Data Store Embedded Driver Configuration
```java=
Configuration configuration = new Configuration.Builder()
             .uri("file:///var/tmp/neo4j.db")
             .build()
```

## 3. Refer
- [Neo4j Wifi features] http://www.vi.w3ki.com/neo4j/neo4j_features_advantages.html
- [CQL Example] https://www.tutorialspoint.com/neo4j/neo4j_where_clause.htm 
- [Neo4j OGM] https://github.com/neo4j/neo4j-ogm
- [Repository ]