简体   繁体   English

使用java创建web浏览器

[英]Using java to create a web browser

Is it possible to use Java to build a web browser like Inte.net Explorer that will open all the web pages and display all the contents?能不能用Java做一个类似Inte.net Explorer的web浏览器,打开所有web页面,显示所有内容?

The only valid answer to that question is:该问题的唯一有效答案是:

Yes, it's possible to use Java to build a web browser.是的,可以使用 Java 构建 Web 浏览器。

However, a web browser is an exceptionally complex piece of software.然而,网络浏览器是一个异常复杂的软件。 Even Google, when building its Google Chrome browser, used existing technology to do it, rather than inventing their own browser from scratch.即使是谷歌,在构建谷歌 Chrome 浏览器时,也使用了现有技术,而不是从头开始发明自己的浏览器。

If your goal is anything other than building and marketing your own browser, you may want to reconsider what exactly you want to accomplish, in order to find a more direct approach.如果您的目标不是构建和营销您自己的浏览器,您可能需要重新考虑您到底想要完成什么,以便找到更直接的方法。

I advise you to take a look at the Lobo Browser project, an open-source java-written web browser.我建议你看看Lobo Browser项目,一个开源的 java 编写的 web 浏览器。 Take a look at the source and see how they did it.看看源代码,看看他们是如何做到的。

Yes, it is possible.对的,这是可能的。 JWebPane is a work in progress migration of Webkit. JWebPane 是一个正在进行中的 Webkit 迁移。 It is supposed to be included in JDK7 but I wouldn't hold my breath. 它应该包含在 JDK7 中,但我不会屏住呼吸。

JWebPane browser = new JWebPane();
new JFrame("Browser").add(browser);
browser.load(someURL);

Yes, it's possible, and here's what you would need to start looking at.是的,这是可能的,这就是您需要开始研究的内容。

First, search for an HTML renderer in Java.首先,在 Java 中搜索 HTML 渲染器。 An example would be JWebEngine.一个例子是 JWebEngine。 You can start by manually downloading HTML pages and verifying that you can view them.您可以先手动下载 HTML 页面并验证您是否可以查看它们。

Second, you need to handle the networking piece.其次,您需要处理网络部分。 Read a tutorial on sockets, or use an HTTP Client such as the Apache HTTPClient project.阅读有关套接字的教程,或使用 HTTP 客户端,例如 Apache HTTPClient 项目。

Edit: Just to add one more thought, you should be honest with yourself about why you would work on this project.编辑:再补充一个想法,你应该诚实地告诉自己为什么要从事这个项目。 If it's to rebuild IE, FF, that is unrealistic.如果是重建IE、FF,那是不现实的。 However, what you might get out of it is learning what the major issues are with browser development, and that may be worthwhile.但是,您可能会从中得到了解浏览器开发的主要问题是什么,这可能是值得的。

Take a look at the JEditorPane class.看看JEditorPane类。 It can be used to render HTML pages and could form the basis of a simple browser.它可以用来渲染 HTML 页面,并且可以构成一个简单浏览器的基础。

Yes.是的。 One of the projects in Java After Hours shows you how to build a simple web browser. Java After Hours中的一个项目向您展示了如何构建一个简单的 Web 浏览器。 It's not nearly as full-featured as IE or Firefox of course (it's only one chapter in the book), but it will show you how to get started.当然,它不像 IE 或 Firefox 那样全功能(这只是书中的一章),但它会告诉你如何开始。

The hardest thing will be the rendering component.最难的将是渲染组件。 Java7 will include JWebPane, that internally uses WebKit. Java7 将包括内部使用 WebKit 的 JWebPane。 Here you can find some screenshots .在这里你可以找到一些截图

I develop this browser for my college project may be this helpful for you我为我的大学项目开发​​这个浏览器可能你有帮助

My Button is open source java web browser. My Button 是开源的 java web 浏览器。

Develop for school and college projects and learning purpose.为学校和大学项目和学习目的而开发。 Download source code extract .zip file and copy “mybutton” folder from “parser\mybutton” to C:\下载源代码解压 .zip 文件并将“mybutton”文件夹从“parser\mybutton”复制到 C:\

Import project “omtMyButton” in eclipse.在eclipse中导入项目“omtMyButton”。 Require Java 6.需要 Java 6。

Download .exe and source code : https://sourceforge.net/projects/omtmybutton/files/下载 .exe 和源代码: https ://sourceforge.net/projects/omtmybutton/files/

There's no sense in building your own web browser in Java.用 Java 构建自己的 Web 浏览器是没有意义的。 It's a very complex software.这是一个非常复杂的软件。 I would say it's more complex than an operating system.我会说它比操作系统更复杂。 AFAIK there are ~600 software engineers working full time on Google Chrome. AFAIK 大约有 600 名软件工程师在 Google Chrome 上全职工作。 I don't know how many engineers work on Mozilla Firefox and Microsoft Edge (Chromium).我不知道有多少工程师在 Mozilla Firefox 和 Microsoft Edge (Chromium) 上工作。

So, I would recommend that you just take an existing web engine and integrate it into your Java app.因此,我建议您只使用现有的 Web 引擎并将其集成到您的 Java 应用程序中。

Here's the options you have, both commercial and open-source:这是您拥有的商业和开源选项:

JavaFX JavaFX

JavaFX is available in Java 8-10. JavaFX 在 Java 8-10 中可用。 It provides the WebView control that you can embed into your JavaFX application to display HTML and web pages.提供WebView控件,您可以将其嵌入到 JavaFX 应用程序中以显示 HTML 和网页。 It's based on WebKit and renders HTML off-screen using Java Graphics API.它基于 WebKit 并使用 Java Graphics API在屏幕外呈现 HTML。 It's lightweight .它很 In Java 11 JavaFX is no longer available.在 Java 11 中,JavaFX 不再可用。 It was extracted into a separate project — OpenJFX .它被提取到一个单独的项目 - OpenJFX中。

JxBrowser浏览器

It's a commercial library.这是一个商业图书馆。 It provides the BrowserView controls for Swing, JavaFX, SWT.它为 Swing、JavaFX、SWT 提供BrowserView控件。 It's based on Chromium, so the modern web pages look exactly as in Google Chrome.它基于 Chromium,因此现代网页看起来与 Google Chrome 中的完全一样。 It supports two rendering modes : off-screen (lightweight) and hardware accelerated (GPU-accelerated, heavyweight).它支持两种渲染模式离屏(轻量级)和硬件加速(GPU 加速,重量级)。

JCEF JCEF

It's an open-source library that represents Java port for CEF (C/C++).它是一个开源库,代表CEF (C/C++) 的 Java 端口。 As far as I know it supports only Swing.据我所知,它只支持 Swing。 It's based on Chromium, so the modern web pages look exactly as in Google Chrome.它基于 Chromium,因此现代网页看起来与 Google Chrome 中的完全一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM