解决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;
    }

 

posted @ 2019-03-05 16:27  RivenLw  阅读(2189)  评论(0编辑  收藏  举报