如何为 netbeans java 添加 jxbrowser 的许可证密钥?
Posted
技术标签:
【中文标题】如何为 netbeans java 添加 jxbrowser 的许可证密钥?【英文标题】:How to add license key for jxbrowser for netbeans java? 【发布时间】:2020-12-02 06:02:03 【问题描述】:我正在尝试在我的 java 应用程序中添加 jxbrowser,但我无法运行我的应用程序,因为它一直告诉我找不到我的许可证。我从网站获得了一个免费许可证,我无法在下面的代码中显示许可证密钥,但我想问我如何配置和设置许可证密钥,因为我一直收到错误。你参考下面。我想知道我是否在我的情况下正确设置了许可证。如果您在下面看到,我将许可证密钥替换为全“#”,因为我不能让人们查看它以防万一它被盗。请告诉我如何解决我的问题。
public class locate extends javax.swing.JFrame
/**
* Creates new form locate
*/
public locate()
initComponents();
open_site();
Browser browser;
BrowserView view;
private void open_site()
Engine engine = Engine.newInstance(
EngineOptions.newBuilder(HARDWARE_ACCELERATED)
.licenseKey("##############################################################")
.build());
System.setProperty("jxbrowser.license.key", "###########################################################");
//BrowserUtil;
browser = new Browser();
view = new BrowserView(browser);
GoogleMapsPanel.add(view, BorderLayout.CENTER);
browser.addTitleListener((TitleEvent evt) ->
setTitle(evt.getTitle());
);
browser.addConsoleListener((ConsoleEvent evt) ->
System.out.println("LOG: " + evt.getMessage());
);
browser.addLoadListener(new LoadAdapter()
@Override
public void onFinishLoadingFrame(FinishLoadingEvent evt)
evt.getBrowser().setZoomLevel(-2);
);
browser.loadURL("/Users/jacksonseow/NetBeansProjects/PleaseWork/src/pleasework/googlemaps.html");
错误:
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at com.teamdev.jxbrowser.chromium.internal.ipc.IPC.getDefault(SourceFile:89)
at com.teamdev.jxbrowser.chromium.BrowserContext.<init>(SourceFile:61)
at com.teamdev.jxbrowser.chromium.BrowserContext.<clinit>(SourceFile:29)
at com.teamdev.jxbrowser.chromium.Browser.<init>(SourceFile:296)
at pleasework.locate.open_site(locate.java:241)
at pleasework.locate.<init>(locate.java:37)
at pleasework.locate$7.run(locate.java:324)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.RuntimeException: JxBrowser license check failed: No valid license found.
【问题讨论】:
【参考方案1】:从给定的源代码中,我看到您将 JxBrowser 7 和 6 混合在一个 Java 应用程序中。以下代码属于7:
Engine engine = Engine.newInstance(
EngineOptions.newBuilder(HARDWARE_ACCELERATED)
.licenseKey("###############")
.build());
以下行属于 JxBrowser 6:
browser = new Browser();
view = new BrowserView(browser);
JxBrowser 7 和 6 使用不同的许可证密钥。我假设您申请了 JxBrowser 7 的 30 天免费评估密钥,并尝试将其与 JxBrowser 6 一起使用。它不会那样工作。如果您拥有 JxBrowser 7 的有效许可证密钥,则不应使用 JxBrowser 6。
我建议您更新您的示例并在您的 Java 应用程序中仅使用 JxBrowser 7:
Engine engine = Engine.newInstance(
EngineOptions.newBuilder(HARDWARE_ACCELERATED)
.licenseKey("########")
.build());
System.setProperty("jxbrowser.license.key", "##########");
//BrowserUtil;
Browser browser = engine.newBrowser();
BrowserView view = BrowserView.newInstance(browser);
GoogleMapsPanel.add(view, BorderLayout.CENTER);
browser.on(TitleChanged.class, event -> setTitle(evt.getTitle()));
browser.on(ConsoleMessageReceived.class, event ->
System.out.println("LOG: " + evt.getMessage()));
browser.navigation().on(FrameLoadFinished.class, event ->
event.frame().browser().zoom().level(ZoomLevel.P_80);
);
browser.navigation().loadUrl("/Users/jacksonseow/NetBeansProjects/PleaseWork/src/pleasework/googlemaps.html");
有关如何从 JxBrowser 6 切换到 7 API 的更多详细信息,您可以在我们的迁移指南中找到:https://jxbrowser-support.teamdev.com/docs/guides/migration/v6-v7.html
【讨论】:
以上是关于如何为 netbeans java 添加 jxbrowser 的许可证密钥?的主要内容,如果未能解决你的问题,请参考以下文章
如何为 NetBeans 设置 Tomcat 管理器应用程序用户名和密码?