SpringBoot啟動后啟動內(nèi)嵌瀏覽器的方法
1、下載內(nèi)嵌瀏覽器Jar包
下載地址:點(diǎn)擊下載
2、項(xiàng)目下加入對應(yīng)jar;然后右鍵:Add as Library...
3、添加啟動項(xiàng)目后事件
效果:內(nèi)嵌瀏覽器打開指定頁面,全屏
import com.teamdev.jxbrowser.chromium.Browser; import com.teamdev.jxbrowser.chromium.swing.BrowserView; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import javax.swing.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; /** * @author 魯達(dá) * createTime 2019-12-29 20:51 **/ @Component public class ApplicationRunnerImpl implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { String url = "http://localhost:9028/open/index"; JFrame frame = new JFrame(); // 谷歌內(nèi)核瀏覽器 Browser browser = new Browser(); BrowserView view = new BrowserView(browser); //禁用close功能 // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //隱藏任務(wù)欄圖標(biāo) // frame.setType(JFrame.Type.UTILITY); // //不顯示標(biāo)題欄,最大化,最小化,退出按鈕 frame.setUndecorated(true); //尺寸 // frame.setSize(500, 500); //坐標(biāo) frame.setLocation(0, 0); frame.add(view); //全屏顯示 frame.setExtendedState(JFrame.MAXIMIZED_BOTH); // 是否顯示 frame.setVisible(true); //是否在屏幕最上層顯示 frame.setAlwaysOnTop(true); //加載地址 browser.loadURL(url); // System.out.println(frame.getX()); // System.out.println(frame.getY()); // list.add(frame); frame.addWindowListener(new WindowAdapter() { // 窗口關(guān)閉時間監(jiān)聽 @Override public void windowClosing(WindowEvent e){ System.out.println("窗口關(guān)閉..."); } }); } }
4、然后在ide 的run--->VM Options里加上一句-Djava.awt.headless=false
解決問題:java.awt.HeadlessException運(yùn)行時異常
5、pom.xml文件添加依賴
解決問題:打包找不到依賴的問題
<!--內(nèi)嵌瀏覽器--> <dependency> <groupId>jxbrowser-6.14</groupId> <artifactId>jxbrowser-6.14</artifactId> <version>6.14</version> <scope>system</scope> <systemPath>${project.basedir}\src\main\resources\lib\jxbrowser-6.14.jar</systemPath> </dependency> <dependency> <groupId>jxbrowser-win32-6.14</groupId> <artifactId>jxbrowser-win32-6.14</artifactId> <version>6.14</version> <scope>system</scope> <systemPath>${project.basedir}\src\main\resources\lib\jxbrowser-win32-6.14.jar</systemPath> </dependency>
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> </plugins> </build>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
在Java中Collection的一些常用方法總結(jié)
今天給大家?guī)淼闹R是關(guān)于Java的,文章圍繞著Java中Collection的一些常用方法展開,文中有非常詳細(xì)的介紹及代碼示例,需要的朋友可以參考下2021-06-06SpringCloud?Eureka服務(wù)注冊中心應(yīng)用入門詳解
這篇文章主要介紹了Spring?Cloud?Eureka服務(wù)注冊中心入門流程分析,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07maven tomcat plugin實(shí)現(xiàn)熱部署
這篇文章主要介紹了maven tomcat plugin實(shí)現(xiàn)熱部署,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07Apache DolphinScheduler實(shí)現(xiàn)自動化打包單機(jī)/集群部署詳解
這篇文章主要為大家介紹了Apache DolphinScheduler實(shí)現(xiàn)自動化打包單機(jī)/集群部署詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09Java中Timer的schedule()方法參數(shù)詳解
今天小編就為大家分享一篇關(guān)于Java中Timer的schedule()方法參數(shù)詳解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03