Compile and run the sample project
Updated
Set up, compile, and run the sample Server Gateway project provided by Agora.
This page shows you how to implement a basic Hello World program after integrating Server Gateway SDK.
-
Navigate to
my-app/srcand remove thetestfolder.rm -r test -
Open
my-app/src/main/java/com/mycompany/app/App.javaand enter the following code. ReplaceYour TokenandYour App IDwith a valid Video SDK temporary token and your 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(); } }The channel name you use to connect to the Video SDK channel must be the same as the one you used 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.
-
Navigate to
my-appand create alibfolder. Get thelinux-sdkjar file from maven, and extract the files to thelibfolder.mkdir lib cd lib wget https://repo1.maven.org/maven2/io/agora/rtc/linux-sdk/4.0.1/linux-sdk-4.0.1.jar jar xvf linux-sdk-4.0.1.jarThe
versionfield independenciesis the SDK version number, which needs to be updated according to the SDK version you integrate. For the latest SDK version number, refer to the release notes. -
Navigate to
my-appand add thelib/native/linux/x86_64folder to theLD_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 AppThe console prints the following information.
$ java -cp target/agora-rtc-linux-java-1.0-SNAPSHOT.jar App join success
