在使用Netty SSL时,咱们每每会采用netty-tcnative-boringssl组件。可是netty-tcnative-boringssl在Windows上仅有64位版本的,没有32版本的。因为项目须要用于32位的,因此本身编译了一下。html
下面详细记录编译的步骤。git
https://codeload.github.com/netty/netty-tcnative/zip/netty-tcnative-parent-2.0.34.Final
将环境变量 JAVA_HOME 指向 Java 8 32 位目录。github
位置:./pom.xmlapache
注释掉不要的模块,编译速度会快不少,以下:windows
<modules> <module>boringssl-static</module> <!-- <module>openssl-dynamic</module> <module>openssl-static</module> <module>libressl-static</module> --> </modules>
<archBits>64</archBits>
修改成:tomcat
<archBits>32</archBits>
这个配置会影响APR组件的平台版本。ui
<property name="tcnativeManifest" value="META-INF/native/${tcnative.snippet};processor=${os.detected.arch}" />-
修改成:google
<condition property="osgi.processor" value="x86" else="${os.detected.arch}"> <equals arg1="${os.detected.arch}" arg2="x86_32"/> </condition> <property name="tcnativeManifest" value="META-INF/native/${tcnative.snippet};processor=${osgi.processor}"/>
这个修改的目的是生成适合OSGi环境使用的Bundle-NativeCode配置。不作这个修改的话,在OSGi环境下dll文件文件会找不到。spa
位置:./vs2010.vcxproj.static.template日志
<PropertyGroup Label="Globals"> <ProjectName>netty_tcnative</ProjectName> <RootNamespace>netty_tcnative</RootNamespace> <ProjectGuid>{42EB387C-0D16-471E-8859-C2CF31F8094D}</ProjectGuid> </PropertyGroup>
修改成:
<PropertyGroup Label="Globals"> <ProjectName>netty_tcnative</ProjectName> <RootNamespace>netty_tcnative</RootNamespace> <ProjectGuid>{42EB387C-0D16-471E-8859-C2CF31F8094D}</ProjectGuid> <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> </PropertyGroup>
<PlatformToolset>v140</PlatformToolset>
修改成:
<PlatformToolset>v141</PlatformToolset>
这两项修改是让vs2010.vcxproj项目跟编译环境相匹配。
位置:./openssl-dynamic/src/main/c/jnilib.c
#ifndef TCN_BUILD_STATIC JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { return JNI_OnLoad_netty_tcnative0(vm, reserved); } JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved) { JNI_OnUnload_netty_tcnative0(vm, reserved); }
修改成:
#ifndef TCN_BUILD_STATIC JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { return JNI_OnLoad_netty_tcnative0(vm, reserved); } JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) { JNI_OnUnload_netty_tcnative0(vm, reserved); }
不作这个修改的话,会报连接错误。
git clone https://boringssl.googlesource.com/boringssl
因为代码来自googlesource,因此须要科*上网。将boringssl的源码放到./boringssl-static/target目录下。
# 进入到32位编译环境 call "D:\Program1\vs\2017-community\VC\Auxiliary\Build\vcvars32.bat" # 打包 mvn package –X
编译过程当中因为环境的不一样,可能会出现各类问题。遇到问题时,耐心一些,参考错误日志,一个一个地解决就能够了。
为方便你们使用,本文附带了一个编译好的文件。以下: