SWT工程發佈免安裝exe應用

創建SWT工程

在Eclipse中安裝WindowBuilder插件,可快速搭建SWT工程。通過WindowBuilder創建一個HelloWorldSWT工程,界面如下:

HelloWorld的代碼如下:

	protected void createContents() {
		shlSwthelloWorld = new Shell();
		shlSwthelloWorld.setSize(342, 342);
		shlSwthelloWorld.setText("SWT-Hello World");
		
		text = new Text(shlSwthelloWorld, SWT.BORDER);
		text.setBounds(10, 73, 322, 237);
		
		Button btnHellosend = new Button(shlSwthelloWorld, SWT.NONE);
		btnHellosend.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				text.setText("SWT, Hello World!");
			}
		});
		btnHellosend.setBounds(10, 32, 94, 27);
		btnHellosend.setText("Hello_Send");
		
		btnClearcontent = new Button(shlSwthelloWorld, SWT.NONE);
		btnClearcontent.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				text.setText("");
			}
		});
		btnClearcontent.setBounds(238, 32, 94, 27);
		btnClearcontent.setText("Clear");

	}

導出jar包

選中工程點擊【Export】–【Runnable JAR File】–【Package required libraries into generated JAR】–【finish】

發佈EXE應用

1、安裝exe4j,適配windows、macOS、linux,可自行選擇,其中windows是安裝版,macOS/linux是免安裝版,直接在安裝軟件中拖拽源安裝文件包到本地即可。
2、使用exe4j,需注意以下幾個點:

  1. Choose Project Type,如下圖所示:
  2. Executable info – 32-bit or 64-bit,勾選【Generate 64-bit executable】,如下圖
  3. 在JRE處選擇導入的Jar包,並在 Main class from 選擇 org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
  4. 在Splash screen – 【Configure search sequence】將jre的文件夾copy一份到導出exe的文件夾中,如下圖
  5. 其餘的大部分都可以默認,點擊【finish】
    這樣就可以實現免安裝且client端無需安裝java-jre也可打開執行。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章