openoffice4.1.5 Linux环境无法通过代码启动

springboot通过Java代码Runtime.getRuntime().exec(OpenOffice_Home+soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard ),在Windows环境能正常启动openoffice服务器,但是部署到Linux服务器却跑不起来。可以使用.sh脚本完美解决

#! /bin/sh
cd /opt/openoffice4/program
./soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

从官网下载openoffice的Linux安装包

http://www.openoffice.org/download/index.html

默认会安装到 /opt/openoffice4

详解整个流程

//局部代码,非完整代码
private String OpenOffice_HOME ="/opt/openoffice4";

String command = OpenOffice_HOME + "/program/soffice -headless -accept=\"socket,host=127.0.0.1,port=" + i + ";urp;\" -nofirststartwizard &";


process = Runtime.getRuntime().exec(command);

我想出现这个问题就是上述代码通过.exec控制openoffice服务的开关,出现这个问题的原因可能在于java通过Runtime.getRuntime().exec(),这个命令根本无法通过代码控制openoffice的开启和关闭。那么这个时候就需要转换一下思路,我把控制openoffice启动的命令放到.sh脚本里,然后通过Runtime.getRuntime().exec()启动这个脚本不就行了?

//xxxx可以是你的项目名,非完整代码
String command = "/root/XXXX/runOpenOffice.sh";//采用脚本的方式开启openoffice

process = Runtime.getRuntime().exec(command);

runOpenOffice.sh

#! /bin/sh
cd /opt/openoffice4/program
./soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

stopOpenOffice.sh

#! /bin/sh
ps -ef |grep soffice |grep -vE 'grep|soffice\.bin'|awk '{print $2}'| xargs kill

通过这种方式,解决了我的问题。开关openoffice道理一样,都是通过Runtime.getRuntime().exec()调用Linux服务器下 /root/runOpenOffice.sh和/root/stopOpenOffice.sh。

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值