java - 使用 Java 在 Eclipse 中进行 CEF 开发

标签 java chromium-embedded

我正在尝试为 Java 应用程序开发浏览器,我发现 JCEF 。我做了这个guide没有任何错误。现在我想尝试简单的示例“MainFrame.Java”,它也是构建的。 我在 eclipse 中创建了一个项目,将 jar 文件添加到库中并复制了 MainFrame 文件。

如果我运行它,我会收到此错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jcef in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.cef.CefApp.<init>(CefApp.java:157)
at org.cef.CefApp.getInstance(CefApp.java:246)
at org.cef.CefApp.getInstance(CefApp.java:233)
at test.MainFrame.<init>(MainFrame.java:71)
at test.MainFrame.main(MainFrame.java:154)

我还尝试了此Question中描述的步骤以及评论里的链接。但是如果我下载第一个 step 中的文件我没有所描述的文件或路径。

有人知道我如何让它运行,还是我做得完全错误?

MainFrame文件的代码:

public class MainFrame extends JFrame {
private static final long serialVersionUID = -5570653778104813836L;
private final JTextField address_;
private final CefApp cefApp_;
private final CefClient client_;
private final CefBrowser browser_;
private final Component browerUI_;

/**
 * To display a simple browser window, it suffices completely to create an
 * instance of the class CefBrowser and to assign its UI component to your
 * application (e.g. to your content pane). But to be more verbose, this
 * CTOR keeps an instance of each object on the way to the browser UI.
 */
private MainFrame(String startURL, boolean useOSR, boolean isTransparent) {

    CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
        @Override
        public void stateHasChanged(org.cef.CefApp.CefAppState state) {
            // Shutdown the app if the native CEF part is terminated
            if (state == CefAppState.TERMINATED)
                System.exit(0);
        }
    });
    CefSettings settings = new CefSettings();
    settings.windowless_rendering_enabled = useOSR;
    cefApp_ = CefApp.getInstance(settings);

    client_ = cefApp_.createClient();

    browser_ = client_.createBrowser(startURL, useOSR, isTransparent);
    browerUI_ = browser_.getUIComponent();

    address_ = new JTextField(startURL, 100);
    address_.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            browser_.loadURL(address_.getText());
        }
    });

    getContentPane().add(address_, BorderLayout.NORTH);
    getContentPane().add(browerUI_, BorderLayout.CENTER);
    pack();
    setSize(800, 600);
    setVisible(true);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            CefApp.getInstance().dispose();
            dispose();
        }
    });
}

public static void main(String[] args) {
    new MainFrame("http://www.google.com", OS.isLinux(), false);
}

}

最佳答案

我成功了。我的问题是我构建的二进制文件不正确

关于java - 使用 Java 在 Eclipse 中进行 CEF 开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40528907/

相关文章:

c++ - 在 MFC dll 中使用 cef

C++在自定义线程中创建cef对象

java - Java 中的重复数据删除 API

java - 带有 'static final byte' 的开关盒

Delphi TChromium/DCEF3 - 持续访问冲突

javascript - 递归函数内部的异步调用

python - 将 CEFPython 整合到 Mac 上的 Kivy App 中——键盘输入不起作用

Java-数据存储和自动运行程序?

java - 如何创建具有特定时区的日历?

Java : Quartz scheduler - is there a way I can get next five runs of a scheduled job