This article shows how to create a simple Maven project, integrate the Linux Server Java SDK, and run the app.
Make sure your server meets the following requirements.
Operating system
CPU architecture
If you need to run the SDK on other architectures, submit a ticket to contact technical support.
Performance
Network
*.agora.io
and *.agoralab.co
.See Get Started with Agora to learn how to get an Agora App ID and an RTC temporary token.
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
Navigate to the my-app
folder.
cd my-app
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>
Navigate to my-app/src
and remove the test
folder.
rm -r test
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 RTC temporary token and App ID.
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();
}
}
Navigate to my-app
. Create a lib
folder, get the linux-sdk jar file from maven, and extract the files.
mkdir 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
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
Build the project:
mvn package
Run the app:
java -cp target/agora-rtc-linux-java-1.0-SNAPSHOT.jar App
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