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 build and run a basic app that uses the Server Gateway SDK to connect to a channel.
To build and run the app, take the following steps:
-
Go to
my-app/srcand remove thetestfolder:rm -r test -
Open
my-app/src/main/java/com/mycompany/app/App.javaand add the following code. ReplaceYour Tokenwith a valid temporary token andYour App IDwith 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(); // Load the JNI library 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 must match the one you used to generate the temporary token. The code connects to
test_channel. If you generated the token for a different channel, replacetest_channelwith that channel name. -
In
my-app, create alibfolder. Download thelinux-sdkJAR file from Maven Central and extract it 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 version number in the URL and the file name is the SDK version. Replace it with the version that you integrate. For the latest version, see the release notes.
-
In
my-app, add thelib/native/linux/x86_64folder toLD_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 AppWhen the app connects to the channel, the console prints the following:
join success
