如何为NetBeans Java的jxbrowser添加许可证密钥?

问题描述

我正在尝试在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.

解决方法

从给定的源代码中,我看到您在单个Java应用程序中混合了JxBrowser 7和6。以下代码属于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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...