【发布时间】:2019-11-13 03:14:51
【问题描述】:
我有一个 java 程序,其中包括 org.eclipse.swt 库,如“Display”和“Shell”
这个程序做的第一件事是:
private void authenticationFlow() {
Display display = new Display();
Shell shell = new Shell(display);
final Browser browser;
//some other code here
}
我将此程序导出为可运行的 jar 文件,并且可以在我的 PC 上正常运行。
但是,当试图在没有安装 eclipse 的 PC 上运行它时,程序无法启动。没有任何例外。它只是退出并且不运行其余代码。
我尝试通过创建一堆这样的警告框来进行调试:
private void authenticationFlow() {
popAlertBox(AlertType.INFORMATION, "Nice", "Something happened", "Starting auth");
Display display = null;
try {
display = new Display();
} catch (Exception e) {
popAlertBox(AlertType.ERROR, "Oh oh", "Something went wrong", e.getMessage());
}
popAlertBox(AlertType.INFORMATION, "Nice", "Something happened", "created display");
Shell shell = new Shell(display);
popAlertBox(AlertType.INFORMATION, "Nice", "Something happened", "created shell");
final Browser browser;
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
try {
shell.setLayout(gridLayout);
} catch (Exception e) {
popAlertBox(AlertType.ERROR, "Shell error", "Could not instantiate Shell: ", e.getMessage());
}
//rest of code
和
private void popAlertBox(AlertType type, String title, String header, String contentText) {
Alert alert = new Alert(type);
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(contentText);
alert.setX(GUIMain.getStageX() + GUIMain.getWidth()*0.4);
alert.setY(GUIMain.getStageY()+ GUIMain.getHeight()*0.4);
alert.showAndWait();
}
我最终看到了“Starting auth”警报框,就是这样,程序随即退出。 我从来没有到达“创建的显示”AlertBox。
所以我认为这与 SWT 本身有关。
现在我的问题是
1. Is this really directly related to SWT or am I misunderstanding something.
2. If it is, how can I have this program run on a PC without eclipse installed?
编辑:
我对所有依赖项都使用 maven 这是我的图书馆的图像,包括 swt
我尝试过围绕我的方法,该方法在 try catch 中调用,如下所示:
try{
authenticationFlow();
}catch (Exception e) {
popAlertBox(AlertType.ERROR, "oh oh", "Something went wrong", e.getMessage());
}
popAlertBox(AlertType.INFORMATION, "Nice", "Something happened", "If you see this then something is in fact happening. final popup");
并且没有显示这两个弹出窗口。不是在 catch 块内的那个,也不是后面的那个。
我在 pom.xml 中添加了以下依赖项:
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>swt</artifactId>
<version>3.3.0-v3346</version>
</dependency>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
<version>4.3</version>
</dependency>
它仍然没有在没有安装eclipse的电脑上运行
【问题讨论】: