解決Libreoffice在Linux服務器上,重啟Tomcat但是Libreoffice8100端口還一直占用的問題


解決思路,既然上一個libreoffice沒關閉,導致8100端口被占用,那我們就去關閉它。

 

在OfficeManager.start();方法之前,使用Linux進程操作工具類,找到之前的libreoffice進程,然后殺掉進程。
Linux進程操作工具類請看https://www.cnblogs.com/RivenLw/p/10477488.html

 

/**
     * 連接LibreOffice.org 並且啟動LibreOffice.org
     * 
     * @return
     * @throws Exception 
     */
    public static OfficeManager getOfficeManager() throws Exception {
        
        String osName = System.getProperty("os.name");
        if (Pattern.matches("Linux.*", osName)) {//如果是Linux系統則嘗試先結束上次啟動的Libreoffice
            String pid = LinuxProcessUtil.getPID("libreoffice");
            logger.info("找到pid="+pid);
            if (StringUtils.isNotEmpty(pid)) {
                LinuxProcessUtil.closeLinuxProcess(pid);
            }
        }
        
        DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration();
        // 設置LibreOffice.org 3的安裝目錄
        config.setOfficeHome(getOfficeHome());
        // 端口號
        config.setPortNumber(8100);
        config.setTaskExecutionTimeout(1000 * 60 * 25L);
//         設置任務執行超時為10分鍾
        config.setTaskQueueTimeout(1000 * 60 * 60 * 24L);
//         設置任務隊列超時為24小時
        // 啟動LibreOffice的服務
        OfficeManager getOfficeManager = config.buildOfficeManager();
        getOfficeManager.start();
        return getOfficeManager;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM