I successfully made FastDDS Gen 4.3.0 support the new syntax of FastDDS 3.6.0 to generate JNI-style calls to Java functionality through the following steps. Below is the detailed procedure, and the attached file is a sample of the modified code.
① Modify the FastDDS Gen project, adjust its module parsing, and add absolute path support. Also replace javah with javac (as the new JDK 17 has merged the functionality), and fix a minor bug related to package creation.
② Recompile FastDDS Gen (adjust its code as needed).
③ Use fastdds-gen to generate C and Java code with the old syntax. The main templates used are JavaSource.stg (omit the generation of setter/getter for String types; these will be completed later in IntelliJ IDEA because the template type cannot be converted) and JNISource.stg (old syntax templates, including header files and dictionary variables). Example:
-------------------JavaSource.stg--------------------
$struct.members : { member |
$if(!member.typecode.isType_e)$
public void set$member.javaName$($member.typecode.javaTypename$ $member.name$)
{
$member.name$_ = $member.name$;
}
$endif$
public $member.typecode.javaTypename$ get$member.javaName$()
{
return $member.name$_;
}
}; separator="\n"$
④ Modify the generated HelloWorldPubSubJNII.hpp and HelloWorldPubSubJNI.cxx files. For the .cxx file, address the following issues:
[1] Class redefinition → Solution: Remove the first definition and move the methods to the second one.
[2] Old syntax upgrade → Solution: Refactor with AI (DeepSeek); the AI-generated code should be verified against the FastDDS source code to ensure correctness, and use common parameter replacements (mainly referencing references in FastDDS).
⑤ Fix CMakeLists.txt by adding Java JNI references and including HelloWorldPubSubJNI.cxx, so that the exported DLL supports JNI calls.
⑥ Modify the generated HelloWorldPubSub.java.
⑦ Use Dependency Walker to check whether JNI symbols are successfully exposed (usually at the end of the DLL).
⑧ Write Java code to test whether standalone data sending and receiving functionality works properly.
demo guide.pdf
I successfully made FastDDS Gen 4.3.0 support the new syntax of FastDDS 3.6.0 to generate JNI-style calls to Java functionality through the following steps. Below is the detailed procedure, and the attached file is a sample of the modified code.
① Modify the FastDDS Gen project, adjust its module parsing, and add absolute path support. Also replace
javahwithjavac(as the new JDK 17 has merged the functionality), and fix a minor bug related to package creation.② Recompile FastDDS Gen (adjust its code as needed).
③ Use fastdds-gen to generate C and Java code with the old syntax. The main templates used are
JavaSource.stg(omit the generation of setter/getter forStringtypes; these will be completed later in IntelliJ IDEA because the template type cannot be converted) andJNISource.stg(old syntax templates, including header files and dictionary variables). Example:④ Modify the generated HelloWorldPubSubJNII.hpp and HelloWorldPubSubJNI.cxx files. For the .cxx file, address the following issues:
[1] Class redefinition → Solution: Remove the first definition and move the methods to the second one.
[2] Old syntax upgrade → Solution: Refactor with AI (DeepSeek); the AI-generated code should be verified against the FastDDS source code to ensure correctness, and use common parameter replacements (mainly referencing references in FastDDS).
⑤ Fix CMakeLists.txt by adding Java JNI references and including HelloWorldPubSubJNI.cxx, so that the exported DLL supports JNI calls.
⑥ Modify the generated HelloWorldPubSub.java.
⑦ Use Dependency Walker to check whether JNI symbols are successfully exposed (usually at the end of the DLL).
⑧ Write Java code to test whether standalone data sending and receiving functionality works properly.
demo guide.pdf