Setup and dependency installations
(Windows)
In order to work with this java sample; you must make sure you have java 6 and above. And also have maven, sbt or gradle installed, for dependency management. You can follow this guide to install Java for windows.
We use SBT for this demo.
STEP 1: Install JAVA . Download the installer and click on the download to run it. Both the JDK and the JRE are installed. Follow the instructions in the guide, to include the JDKs 'bin' directory in the path.
STEP 2: Verify that the installation is done and that you have both the JDK and the JRE installed.
Verify the JRE
>java --version
Verify the JDK
>javac --version
STEP 3: Install SBT
Installing SBT on windows is easy. Just download the .msi file and run the install process.
STEP 4: Create your project folder.
>md projectName
Create directory and CD to directory
>cd projectName
Using your favorite editor, create build.sbt file in your root folder and set up dependencies in the file.
libraryDependencies += "com.sparkjava" % "spark-core" % "2.5.4"
To run the application, use the following command:
>sbt run
Go to your route to see your web application: http://localhost:4567/yourUrl
To stop the application:
ctrl+c
To enable logging, you can add the following dependency to build.sbt
libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.21"
Create the directory structure:
projectName> mkdir src\main\java
src\main\java> mkdir com\africastalking\app
Download the AfricasTalkingGateway.java file from the AT docs website and copy it into your app. We are storing this file in a folder utils.
projectName> cd src\main\java\com\africastalking\app
\africastalking\app> md util
In the AfricasTalkingGateway.java file, include the line:
package com.africastalking.app.util;
You can now build your application.
With your environment set up, you are now ready to start writing your application.
(Linux - *unix variants / mac)
In order to work with this java sample; you must make sure you have java 6 and above. And also have maven, sbt or gradle installed, for dependency management. You can follow this guide to install Java for Linux.
We use SBT for this demo.
STEP 1: Install JAVA . Download the installer and click on the download to run it. Both the JDK and the JRE are installed. Follow the instructions in the guide, to include the JDKs 'bin' directory in the path.
STEP 2: Verify that the installation is done and that you have both the JDK and the JRE installed.
Verify the JRE
$java --version
Verify the JDK
$javac --version
STEP 3: Install SBT
Installing SBT on linux is easy. You can install SBT from the commandline.
STEP 4: Create your project folder.
$mkdir projectName
Create directory and CD to directory
$mkdir projectName
Using your favorite editor, create build.sbt file in your root folder and set up dependencies in the file.
libraryDependencies += "com.sparkjava" % "spark-core" % "2.5.4"
To run the application, use the following command:
$sbt run
Go to your route to see your web application: http://localhost:4567/yourUrl
To stop the application:
ctrl+c
To enable logging, you can add the following dependency to build.sbt
libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.21"
Create the directory structure:
projectName$ mkdir src/main/java
src/main/java$ mkdir com/africastalking/app
Download the AfricasTalkingGateway.java file from the AT docs website and copy it into your app. We are storing this file in a folder utils.
projectName$ cd src/main/java/com/africastalking/app
/africastalking/app$ mkdir util
In the AfricasTalkingGateway.java file, include the line:
package com.africastalking.app.util;
You can now build your application.
With your environment set up, you are now ready to start writing your application.