The jitsi-sctp project creates a JNI wrapper around the usrsctp lib and provides a set of Java classes to further flesh out a convenient Java SCTP API, which can be used on Linux, MacOS X, FreeBSD and Windows.
Because JNI has a complex build process multiplied by being platform dependent, this project has multiple Maven modules to try and separate each of the phases necessary from start to finish. The maven modules are laid out as follows:
`-- jitsi-sctp
|-- jniwrapper
| |-- java
| |-- jnilib
| `-- native (produces platform specific artifact classified by OS & CPU architecture)
|-- sctp
`-- usrsctp (produces platform specific artifact classified by OS & CPU architecture)
- The
usrsctpmodule handles the compilation of theusrsctpsource library. This maven module produces a platform-specific artifact containing a platform-specific build of theusrsctpstatic library and correspondingCAPI-header. The module is built only when thebuild-usrsctpprofile is enabled by passing the-Pbuild-usrsctpswitch tomvn. Execution ofmvn package -Pbuild-usrsctp -f pom.xml -pl org.jitsi:usrsctpwill create a jar that will include the native library and the necessary include headers for current platform. A resultingjarartifact has maven classifier specified as a concatenation ofusrsctpcommit and target platform. For example, an artifact forLinuxmight be named asusrsctp-1.0-SNAPSHOT-7a8bc9a-linux-x86_64.jarwith an example content:
$ tree usrsctp-1.0-SNAPSHOT-7a8bc9a-linux-x86_64 --noreport
usrsctp-1.0-SNAPSHOT-7a8bc9a-linux-x86_64
|-- META-INF
| |-- MANIFEST.MF
| `-- maven
| `-- org.jitsi
| `-- usrsctp
| `-- pom.xml
|-- git.properties
|-- include
| `-- usrsctp.h
`-- lib
`-- libusrsctp.a
-
The
jniwrappermodule has 3 nested modules:-
The
jniwrapper-javamodule includes the Java portion of the JNI API and interacts with the native code. The artifact produced by this module has Java classes to interact with nativeusrsctpwrapper, it also has necessaryJNICheaders, generated from Java classes. An example of artifact content:$ tree jniwrapper-java-1.0-SNAPSHOT --noreport jniwrapper-java-1.0-SNAPSHOT |-- META-INF | |-- MANIFEST.MF | `-- maven | `-- org.jitsi | `-- jniwrapper-java | |-- pom.properties | `-- pom.xml |-- cz | `-- adamh | `-- utils | `-- NativeUtils.class |-- native | `-- headers | `-- org_jitsi_modified_sctp4j_SctpJni.h `-- org `-- jitsi_modified `-- sctp4j |-- EightArgumentVoidFunc.class |-- FourArgumentIntFunc.class |-- IncomingSctpDataHandler.class |-- OutgoingSctpDataHandler.class `-- SctpJni.class -
The
jniwrapper-nativemodule contains theCportion of the JNI API that bridges the Java and theusrsctpnative lib. The module is built only when thebuild-jnisctpprofile is enabled by passing the-Pbuild-jnisctpswitch tomvn. It depends on two other modules:usrsctpmodule, because it needs the pre-builtusrsctpstatic library and include headers. The version ofusrsctpartifact used is specified by propertyusrsctp_commit_idinjniwrapper/pom.xmland having short commit hash of pre-builtusrsctp;jniwrapper-javamodule, because it needjava -hgeneratedJNIheader file to match theCimplementation.
The
compilebuild phase ofjniwrapper-nativemodule will create a new dynamic jni lib intarget/jnisctp_cmake/{os}-{arch}/install. E.g. onLinuxit produces dynamic librarytarget/jnisctp_cmake/linux-x86_64/install/libjnisctp.so.The
packagebuild phase ofjniwrapper-nativemodule will create a platform specificjarthat includes the java code and the shared native library for current platform. It is assumed thatusrsctpartifact for target platform is already available inMaven. Below is an example of artifact produced bymvn package -Pbuild-usrsctp -Pbuild-jnisctp -f pom.xml -pl org.jitsi:jniwrapper-native -amis presented:$ tree jniwrapper-native-1.0-SNAPSHOT-linux-x86_64 --noreport jniwrapper-native-1.0-SNAPSHOT-linux-x86_64 |-- META-INF | |-- MANIFEST.MF | `-- maven | `-- org.jitsi | `-- jniwrapper-native | `-- pom.xml `-- lib `-- linux-x86_64 `-- libjnisctp.so
Note: It is intended that platform specific
Mavenartifacts produced byusrsctpandjniwrapper-nativemodules are built on each supported platform independently and published ahead of time to Maven repository before the rest of the artifacts can be built in way which allow them to be used on any of supported platform.- The
jnilibmaven module combines thejniwrapper-javaandjniwrapper-nativeinto a singlejarwhich includes the Java API and the native JNI library that will be loaded at runtime. When built withmvn package -f pom.xml -Pbuild-usrsctp -Pbuild-jnisctp -pl org.jitsi:jnilib -amthejnilibartifact only include nativejnisctplibrary for current platform. To have universal (fat jar or cross-platform jar)jnilibsuitable to run on any supported platform it necessary to build and publish platform-specificjniwrapper-nativeartifacts for all supported platforms in advance and then build withbuild-x-plat-jarprofile enabled via passing-Pbuild-x-plat-jarswitch into Maven. For example, fatjnilibjar could be built withmvn package -Pbuild-x-plat-jar -f pom.xml -pl org.jitsi:jnilib, which will produce fat jar with example content:$ tree jnilib-1.0-SNAPSHOT --noreport jnilib-1.0-SNAPSHOT |-- META-INF | |-- MANIFEST.MF | `-- maven | `-- org.jitsi | |-- jnilib | | `-- pom.xml | |-- jniwrapper-java | | |-- pom.properties | | `-- pom.xml | `-- jniwrapper-native | `-- pom.xml |-- cz | `-- adamh | `-- utils | `-- NativeUtils.class |-- lib | |-- osx-x86_64 | | `-- libjnisctp.jnilib | |-- linux-x86_64 | | `-- libjnisctp.so | |-- freebsd-x86_64 | | `-- libjnisctp.so | `-- windows-x86_64 | |-- jnisctp.dll | `-- jnisctp.pdb |-- native | `-- headers | `-- org_jitsi_modified_sctp4j_SctpJni.h `-- org `-- jitsi_modified `-- sctp4j |-- EightArgumentVoidFunc.class |-- FourArgumentIntFunc.class |-- IncomingSctpDataHandler.class |-- OutgoingSctpDataHandler.class `-- SctpJni.class
-
-
The
sctpmodule contains the Java library on top of the JNI code. The jar built by this is what is intended to be used by other code.
CMake is required to build native libraries.
Native compilers GCC/Clang/Visual C++ required to build native libraries.
- Clone the project and initialize
usrsctpgit submodule.> git clone --recurse-submodules https://github.com/jitsi/jitsi-sctp.git jitsi-sctp - Run
mvn install -Pbuild-usrsctp -Pbuild-jnisctp -f pom.xmlto build bothJavaand native artifacts for current platform and install them into localMavenrepository. If you don't want to re-build native artifactsusrsctpandjniwrapper-nativeand prefer using pre-built version of them fromMavenyou may build and installJavaartifacts viamvn install -f pom.xml. - Depend on the
org.jitsi:sctpartifact to usejitsi-sctpin your project.
The JNI lib will need to be rebuilt if there is a change in the usrsctp version or a change in the JNI wrapper C file.
Changes in usrsctp handled by re-compiling usrsctp artifact from corresponding Maven module.
Changes in JNI wrapper C code are handled by recompiling jniwrapper-native artifact from corresponding maven module.
To re-build native libraries cross-platform CMake build tool, C compiler and linker and JDK must be installed on system used to build.
The following steps can be done to produce an updated version of jitsi-sctp artifact with newer version of usrsctp or jniwrapper-native:
-
Clone the project with
git clone --recurse-submodules https://github.com/jitsi/jitsi-sctp.git. -
[Optional] initialize the usrsctp submodule with
git submodule update --init --recursive:jitsi-sctp/usrsctp/usrsctp> (check out whatever hash/version you want in case it distinct from what is defined by git submodule) -
Produce an updated platform specific
usrsctpartifactjitsi-sctp> mvn clean package install -Pbuild-usrsctp -f pom.xml -pl org.jitsi:usrsctp -
[Optional] Update
<usrsctp_commit_id>property injniwrapper/pom.xmlto specify desired version ofusrsctpto use. -
Produce an updated platform specific
jniwrapper-nativeartifact and publish it to Maven.jitsi-sctp> mvn clean package install -Pbuild-jnisctp -f pom.xml -pl org.jitsi:jniwrapper-native -
[Optional] Repeat steps
1 - 5on each of supported platforms:Linux,Mac OSX,FreeBSD,Windows. -
Once
usrsctpandjniwrapper-nativeartifacts built and published to Maven repository for each supported platform (Windows,Linux,Mac,FreeBSD) with steps1 - 6, an updated fat jar could be build and installed with following command:jitsi-sctp> mvn clean package install -Pbuild-x-plat-jar -f pom.xml -
To produce
jitsi-sctpartifact usable only on current platform steps3 - 7can be skipped and following command could be used instead:jitsi-sctp> mvn clean package install -Pbuild-usrsctp -Pbuild-jnisctp -f pom.xml