Skip to main content

You are looking at Server Gateway v3.x Docs. The newest version is  Server Gateway 4.x

Linux C++
Linux Java

Integrate the SDK

This article shows how to create a simple Maven project, integrate the Java SDK, and run the app.

Set up the development environment

Make sure your server meets the following requirements.

Hardware environment

Operating system

  • Ubuntu (14.04 or higher)
  • CentOS (6.6 or higher)

CPU architecture

  • arm64
  • x86-64

If you need to run the SDK on other architectures, submit a ticket to contact technical support.

Performance

  • CPU:8-core, 1.8 GHz or higher.
  • 2 GB of RAM or higher. 4 GB or higher is recommended.

Network

  • The server is connected to the internet and has an internet IP.
  • The server can access *.agora.io and *.agoralab.co.

Software environment

  • Apache Maven or other build tools. This page uses Apache Maven as an example.
  • JDK 8

Get an Agora App ID and an Video SDK Temporary Token

See Get Started with Agora to learn how to get an Agora App ID and an Video SDK temporary token.

Create a Maven project

See Maven in Five Minutes to create a Maven project.

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
Copy

Integrate the SDK

  1. Navigate to the my-app folder.

    cd my-app
    Copy
  2. Open pom.xml and replace the content with the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>agora-rtc-linux-java</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
    <dependency>
    <groupId>io.agora.rtc</groupId>
    <artifactId>linux-sdk</artifactId>
    <version>3.7.200.21</version>
    </dependency>
    </dependencies>

    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <configuration>
    <createDependencyReducedPom>true</createDependencyReducedPom>
    </configuration>
    <executions>
    <execution>
    <phase>package</phase>
    <goals>
    <goal>shade</goal>
    </goals>
    <configuration>
    <transformers>
    <transformer
    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
    <mainClass>App</mainClass>
    </transformer>
    </transformers>
    </configuration>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>
    </project>
    Copy
Refer to mvnrepository for other integration methods, such as Gradle.

Implement a HelloWorld program

  1. Navigate to my-app/src and remove the test folder.

    rm -r test
    Copy
  2. Navigate to my-app/src/main/java/com/mycompany/app/App.java and enter the following code. Replace Your Token and Your App ID with your Video SDK temporary token and App ID.

    The channel name you use to connect to the Video SDK channel must be the same as the one you use to generate your Video SDK temporary token. In the following code, the channel name is set to "test_channel". If you use a different channel name to generate your Video SDK temporary token, replace "test_channel" with your own channel name.
    import io.agora.rtc.SDK;
    import io.agora.rtc.AgoraRtcConn;
    import io.agora.rtc.AgoraService;
    import io.agora.rtc.AgoraServiceConfig;
    import io.agora.rtc.DefaultRtcConnObserver;
    import io.agora.rtc.RtcConnInfo;

    public class App {

    public static class ConnObserver extends DefaultRtcConnObserver {
    @Override
    public void onConnected(AgoraRtcConn conn, RtcConnInfo rtcConnInfo, int reason) {
    System.out.println("join success");
    }
    }

    public static void main(String[] args) throws Exception {
    String token = "Your Token";
    SDK.load(); // ensure JNI library load
    AgoraService service = new AgoraService();
    AgoraServiceConfig config = new AgoraServiceConfig();
    config.setEnableAudioProcessor(0);
    config.setEnableAudioDevice(0);
    config.setEnableVideo(0);
    config.setContext(0);
    config.setAppId("Your App ID");
    service.initialize(config);

    AgoraRtcConn conn = service.agoraRtcConnCreate(null);

    conn.registerObserver(new ConnObserver());

    conn.connect(token, "test_channel", "1");

    Thread.sleep(2000);
    conn.disconnect();
    conn.destroy();
    service.destroy();
    }
    }
    Copy
  3. Navigate to my-app. Create a lib folder, get the linux-sdk jar file from maven, and extract the files in the lib folder.

    mkdir lib
    cd lib
    wget https://repo1.maven.org/maven2/io/agora/rtc/linux-sdk/3.7.200.21/linux-sdk-3.7.200.21.jar
    jar xvf linux-sdk-3.7.200.21.jar
    Copy
  4. Navigate to my-app. Add the lib/native/linux/x86_64 folder to the LD_LIBRARY_PATH.

    export LD_LIBRARY_PATH=lib/native/linux/x86_64/:$LD_LIBRARY_PATH
    Copy
  5. Build the project:

    mvn package
    Copy
  6. Run the app:

    java -cp target/agora-rtc-linux-java-1.0-SNAPSHOT.jar App
    Copy

The console prints the following information if the app runs successfully.

$ java -cp target/agora-rtc-linux-java-1.0-SNAPSHOT.jar App
join success
Copy

Server Gateway