[FASTDDS]02-安装fast-gen
原创 https://blog.51cto.com/u_6650004/6114605安装fast-gen
fast-gen
是一个java
程序,因此需要安装openjdk
和gradle
。
export FAST_DDS_ROOT=/home/V01/uidq8207/work/code/third_party/Fast-DDS-GIT/
sudo apt install openjdk-8-jdk
cd ${FAST_DDS_ROOT}
git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git
cd Fast-DDS-Gen
gradle assemble
# 如果 gradle assemble 执行失败,请使用下面的命令代替
./gradlew assemble
安装完后,将包含以下package
:
share/fastddsgen
:生成的java
应用scripts
:一些用户友好的脚本
安装错误处理
java版本问题
$ ./gradlew assemble
> Task :submodulesUpdate
Cloning into '/work/code/third_party/Fast-DDS-GIT/Fast-DDS-Gen/thirdparty/idl-parser'...
Submodule path 'thirdparty/idl-parser': checked out '905636a05379444dd01f29e827594120e8197d20'
> Task :idl-parser:compileJava FAILED
/work/code/third_party/Fast-DDS-GIT/Fast-DDS-Gen/thirdparty/idl-parser/src/main/java/com/eprosima/idl/context/Context.java:1269: error: cannot access org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory
return new org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory()
^
bad class file: /home/V01/uidq8207/.gradle/caches/modules-2/files-2.1/org.openjdk.nashorn/nashorn-core/15.4/f67f5ffaa5f5130cf6fb9b133da00c7df3b532a5/nashorn-core-15.4.jar(org/openjdk/nashorn/api/scripting/NashornScriptEngineFactory.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
1 error
> Task :buildIDLParser FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':idl-parser:compileJava'.
> Compilation failed; see the compiler error output for details.
根据上面的信息,是java
版本信息有错,我们本地是52
版本,但jar
是55
版本。
主版本(Major Version)和JDK版本的对应关系如下表所示。
主版本(Major Version) 对应JDK版本
52 JDK 8
53 JDK 9
54 JDK 10
55 JDK 11
因此,我们选择安装jdk11
,命令如下:
sudo apt install openjdk-11-jdk
# 选择我们刚刚安装的jdk-11,此时输入0即可
sudo update-alternatives --config java
# 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
# 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
# * 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
java -version
# openjdk version "11.0.18" 2023-01-17
# OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu118.04.1)
# OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)
再次运行./gradlew assemble
,该问题得到解决。