【问题标题】:JWebBrowser not working on the other computersJWebBrowser 无法在其他计算机上运行
【发布时间】:2018-04-25 11:10:36
【问题描述】:

我正在尝试在我的项目中使用 JWebBrowser。在我的电脑上一切正常。但是当我尝试在其他计算机上使用执行jar时,双击时没有任何反应。下面是示例代码,在我的计算机上运行良好,但在其他计算机上无法运行。我该如何解决这个问题?

有没有办法获取执行 jar 的错误消息,就像我从 Eclipse 控制台得到的一样?

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;

/**
 * @author Christopher Deckers
 */
public class Main extends JPanel {

  public Main() {
    super(new BorderLayout());
    JPanel webBrowserPanel = new JPanel(new BorderLayout());
    webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Native Web Browser component"));
    final JWebBrowser webBrowser = new JWebBrowser();
    webBrowser.navigate("http://www.google.com");
    webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
    add(webBrowserPanel, BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));
    JCheckBox menuBarCheckBox = new JCheckBox("Menu Bar", webBrowser.isMenuBarVisible());
    menuBarCheckBox.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        webBrowser.setMenuBarVisible(e.getStateChange() == ItemEvent.SELECTED);
      }
    });
    buttonPanel.add(menuBarCheckBox);
    add(buttonPanel, BorderLayout.SOUTH);
  }


  public static void main(String[] args) {

    UIUtils.setPreferredLookAndFeel();
    NativeInterface.open();
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        JFrame frame = new JFrame("DJ Native Swing Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new Main(), BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationByPlatform(true);
        frame.setVisible(true);
      }
    });
    NativeInterface.runEventPump();
  }

}

【问题讨论】:

  • 在其他计算机上使用命令java -jar myJar.jar 从控制台运行它。然后你会在控制台看到stacktrace。
  • 我收到以下错误。我的电脑是64位的。有没有办法让 jar 在 32 位和 64 位上都工作? NativeSwing [1]:线程“主”java.lang.UnsatisfiedLinkError 中的异常:无法在 32 位 JVM NativeSwing [1] 上加载 64 位 SWT 库:在 org.eclipse.swt.internal.Library.loadLibrary(未知来源) NativeSwing[1]: at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source) NativeSwing[1]: at org.eclipse.swt.internal.C.(Unknown Source) ..... ......................

标签: java eclipse debugging error-handling jwebbrowser


【解决方案1】:

尝试在eclipse中将默认的JRE版本改为32bit。 或者将 -d32 添加到“编辑启动配置属性”中的 VM 参数中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 2015-06-29
    相关资源
    最近更新 更多