J2V8:编译J2V8最新版Jar包

47 篇文章 1 订阅

J2V8 简介

J2V8 是对 Google 的 JavaScript 引擎 V8 的 Java 封装,J2V8 的开发为Java 或是 Android 可以高效得执行 JavaScript 带来了可能。
Github地址

编译J2V8

在GitHub中,作者主要目的是使用J2V8进行tabris.js这个多平台js引擎的开发,用于在Android设备上执行JavaScript。只提供了Android版本最新的aar包,没有最新的jar包,因此根据作者提供的编译教程进行编译。

Github官方编译教程

win32_x86_64版本

准备编译环境

  • Python2
  • vs2017
  • jdk
  • windows 64位PC

以上是确定需要的,我电脑本身就有一些编译环境已经安装,不确定是否还有其他需要的

clone J2V8的源码

Github源码地址 将代码clone到本地

运行 j2v8-cli.cmd

编译工具链,运行后才可进行后面的编译,每次开始编译都需要运行一次

clone Node.js 源码

nodejs git clone 使用这个命令把nodejs的源码下载下来
nodejs diff apply 将所需修改应用于node.js源代码

开始编译

编译的步骤

Node.js --> CMake --> JNI --> C++ --> Optimize --> Java/Android Build --> Java/Android Test

确定需要编译的版本为win32_x86_64版本

作者提供了多种编译方式,我在编译过程中出了很多错误,需要单步解决bug,故推荐一步一步进行编译。

1. build -t win32 -a x64 Node.js
2. build -t win32 -a x64 j2v8cmake
3. build -t win32 -a x64 j2v8jni
4. build -t win32 -a x64 j2v8cpp
5. build -t win32 -a x64 j2v8optimize
6. build -t win32 -a x64 j2v8java 

编译生成Jar包目录

./build.out/j2v8_{platform}_{abi}-{j2v8_version}.jar

linux_x86_64版本

需要在linux 64环境下进行编译,可搭建linux虚拟机进行编译

编译工具链命令为

source j2v8-cli.sh

单步编译命令前缀改为

build -t linux -a x64

其余步骤相似

编译中出现的错误

在单步编译的话可能报错,遇到错误解决后再继续进行当前步骤的编译。
大部分的错误都是找不到一些编译需要用到的工具,应安装这些工具或添加环境变量后继续。

E:\j2v8\J2V8-master>build -t win32 -a x64 j2v8cpp
Checking Node.js builtins integration consistency...
--------------------------------------------------
V8:      5.4.500.45 (candidate: False)
Node.js: 7.4.0 (release: True)
--------------------------------------------------
Caching Node.js artifacts...
>>> Node.js build-cache used: win32.x64

Microsoft Windows [版本 10.0.16299.431]
Updating Maven configuration (./docker/shared/pom.xml)...
SHELL building win32@x64 => j2v8cpp
'msbuild' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
Traceback (most recent call last):
  File "build.py", line 18, in <module>
    bex.execute_build(args)
  File "E:\j2v8\J2V8-master\build_system\build_executor.py", line 314, in execute_build
    execute_build_step(target_compiler, target_step)
  File "E:\j2v8\J2V8-master\build_system\build_executor.py", line 230, in execute_build_step
    build_system.build(build_step)
  File "E:\j2v8\J2V8-master\build_system\build_structures.py", line 83, in build
    self.exec_build(config)
  File "E:\j2v8\J2V8-master\build_system\shell_build.py", line 27, in exec_build
    self.exec_cmd(shell_str, config)
  File "E:\j2v8\J2V8-master\build_system\build_structures.py", line 96, in exec_cmd
    self.__exec_cmd_core(cmd, config, config.build_cwd)
  File "E:\j2v8\J2V8-master\build_system\build_structures.py", line 105, in __exec_cmd_core
    utils.execute(cmd, cwd)
  File "E:\j2v8\J2V8-master\build_system\build_utils.py", line 157, in execute
    raise subprocess.CalledProcessError(return_code, cmd)
subprocess.CalledProcessError: Command 'cd E:/j2v8/J2V8-master && cd ./cmake.out/win32.x64/ && msbuild j2v8.sln /property:Configuration=Release' returned non-zero exit status 1

解决方案:需要在系统环境变量中的path变量中添加一条路径,如C:\Windows\Microsoft.NET\Framework\v4.0.30319 C:\Windows\Microsoft.NET\Framework64\v4.0.30319

E:\j2v8\J2V8-master>build -t win32 -a x64 j2v8java
Checking Node.js builtins integration consistency...
--------------------------------------------------
V8:      5.4.500.45 (candidate: False)
Node.js: 7.4.0 (release: True)
--------------------------------------------------
Caching Node.js artifacts...
>>> Node.js build-cache used: win32.x64

Microsoft Windows [版本 10.0.16299.431]
Updating Maven configuration (./docker/shared/pom.xml)...
SHELL building win32@x64 => j2v8java
Updating Maven configuration (./pom.xml)...
Copying native lib from: ./cmake.out/win32.x64/Release\libj2v8-windows-x86_64.dll to: src/main/resources/
Using system-var JAVA_HOME
'mvn' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
Traceback (most recent call last):
  File "build.py", line 18, in <module>
    bex.execute_build(args)
  File "E:\j2v8\J2V8-master\build_system\build_executor.py", line 314, in execute_build
    execute_build_step(target_compiler, target_step)
  File "E:\j2v8\J2V8-master\build_system\build_executor.py", line 230, in execute_build_step
    build_system.build(build_step)
  File "E:\j2v8\J2V8-master\build_system\build_structures.py", line 83, in build
    self.exec_build(config)
  File "E:\j2v8\J2V8-master\build_system\shell_build.py", line 27, in exec_build
    self.exec_cmd(shell_str, config)
  File "E:\j2v8\J2V8-master\build_system\build_structures.py", line 96, in exec_cmd
    self.__exec_cmd_core(cmd, config, config.build_cwd)
  File "E:\j2v8\J2V8-master\build_system\build_structures.py", line 105, in __exec_cmd_core
    utils.execute(cmd, cwd)
  File "E:\j2v8\J2V8-master\build_system\build_utils.py", line 157, in execute
    raise subprocess.CalledProcessError(return_code, cmd)
subprocess.CalledProcessError: Command 'cd E:/j2v8/J2V8-master && python E:/j2v8/J2V8-master/build_system/polyfills/cp.py ./cmake.out/win32.x64/Release\libj2v8-windows-x86_64.dll src/main/resources/ && mvn clean verify -e --batch-mode -DskipTests && python E:/j2v8/J2V8-master/build_system/polyfills/mkdir.py build.out && python E:/j2v8/J2V8-master/build_system/polyfills/cp.py target/j2v8_win32_x86_64-5.1.0-SNAPSHOT.jar build.out/' returned non-zero exit status 1

需要安装maven和添加环境变量

欢迎关注我的公众号,持续分析优质技术文章
欢迎关注我的公众号

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值