Jcef embedded browser for windows compilation and use, jcef embedded

Source: Internet
Author: User

Jcef embedded browser for windows compilation and use, jcef embedded
Background

The new requirements received at the end of last year need to make a function of the desktop application originally made with Swing into a Web version and integrate it into the original application, that is, to use an embedded browser. The initial consideration is the WebView provided by JavaFx. The advantage is that other third-party libraries are not required and jdk1.7 starts integration. However, after the development is complete, two serious problems are discovered. One is that there is a complicated curve on the interface, which will cause severe freezing, and the other is that there is a probability that the virtual machine will crash, and the speed is not very satisfactory. Finally, we can only consider changing the embedded browser framework, and then find jcef. Based on chrome, the speed compatibility is good.

Jcef is not described much. If you do not know about jcef, you can click java-cef here. This article mainly describes the jcef compilation process. Because the product only supports the 32-bit jre on the windows platform, therefore, only win32 versions are compiled. The 64-bit compilation process is basically the same. You only need to change the parameters.

Compiling environment
  • CMake 2.8.12.2)
  • Git
  • Visual Studio 2015 (2015 is recommended on the official website because the developer is using version 2015. errors will be reported during VS2010 and VS2013 compilation)
  • Java 1.8 32-bit (1.7 or 1.8 is written on the official website. In fact, if 1.7 is used to compile java, a syntax error occurs. You can modify the source code to avoid it. We recommend that you use 1.8, compile the 64-bit version and use the 64-bit jdk)
  • Python 2.6 or later (Python3 is not supported)
Compilation process

1. Download source code

Use Git to download the jcef source code. clone address: https://bitbucket.org/chromiumembedded/java-cef.git. Of course, you can also download the jcef Source Code directly. We recommend that you use Git Clone, because it is required for building with CMake. the information of the current node in the file under the git directory is used to build the jcef_version.h header file. If it is not the code of git clone, compilation of files related to git will fail, this should be avoided by modifying the compilation script and writing the information obtained through the git file to the dead end. I have not tried it and will not detail the table.

    

2. CMake build VS Project

Create the jcef_build directory under the source code directory (cannot be named at will), open DOS to enter the new directory, enter the command cmake-G "Visual Studio 14 2015"..., and press enter to start building. This is a pitfall. When I edited the file, the newly installed VS2015 reported an error. I couldn't find the compiler. After studying it for a long time, I finally found a sentence. By default, VS2015 installed without C ++ support ...... At that time, the whole person was not good. If you want to write 64-bit code, replace it with the following command: cmake-G "Visual Studio 14 Win64 "... Note that this process will automatically download the current CEF version of Jcef, if the download fails, you can download the package and put it in the/java-cef/third_party/cef directory. The cef number can be found in the cmakelists.txt file under the source code directory.

CEF: http://opensource.spotify.com/cefbuilds/index.html (often cannot open, I FQ to stable open)

 

C ++ projects built by CMake:

  

3. VS build

Use VS to open jcef in jcef_build. select "generate --> Configuration Manager --> change to Release and Win32" for the sln file, select "generate --> Generate solution", and wait until the build is complete.

4. compile java code

Use dos to go to the tools directory of the source code directory and run the compile. bat win32 command.

5. Test Run

Similarly, in the tools directory, run. bat win32 Release simple or run. bat win32 Release detailed. the browser runs normally and compilation is successful.

6. Package

Run make_distrib.bat win32 in the tools directory. The binary_distrib directory is automatically created under the source code Directory, which contains the api documentation, browser Demo, jar and dll used, and resource files.

Usage

Jar: \ java-cef \ binary_disrib \ win32 \ bin

  

Dynamic library and resource files: \ java-cef \ binary_disrib \ win32 \ bin \ lib \ win32 content

Import jcef During encoding to compile successfully. during runtime, classpath specifies the jar package above, and put the content in the win32 Directory of the above dll and other files in a directory, then specify it as-Djava. library. for more information, see run in \ java-cef \ binary_distrib \ win32. bat.

One-click script Compilation

Build_jcef.bat win32 one-click compilation. The script is written in 64-bit compiling mode. You can use win64 as the parameter. However, I have not tried it ......

@ Echo on @ rem set path set SRC_PATH = D: \ java-cefset VS_PATH = C: \ Develop \ VS2015if "% 1" = "" (echo ERROR: please specify a target platform: win32 or win64set ERRORLEVEL = 1 goto end) cd/d % SRC_PATH % mkdir % SRC_PATH % \ jcef_buildcd/d % SRC_PATH % \ jcef_build @ rem CMake build cmake-G "Visual Studio 14 2015 ".. @ rem VS compilation @ echo VS Building Start % VS_PATH % \ Common7 \ IDE \ devenv.exe % SRC_PATH % \ jcef_build \ jcef. sln/rebuild "Release | % 1" @ echo VS Building End @ rem compile java part cd/d % SRC_PATH % \ tools call compile. bat % 1 @ rem package call make_distrib.bat % 1: endExit/B
View Code

 

Conclusion

From compilation to development, as well as various bugs, jcef has little information and has taken many detours. However, the project was successfully delivered. Here, I will take a note and share it with the people who need it. I hope it will be helpful.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.