我想使用openoffice的格式转换功能,需要先开启openoffice的服务,当我手动敲入命令的时候,是可以运行起来的,但是通过Java代码执行却出现拒绝连接的问题,请帮我看看怎么回事
public static String soffice_host = "127.0.0.1";
public static String soffice_port = "8100";
public static Process pro = null;
String commands = "cmd.exe /C C:\\Program Files (x86)\\OpenOffice 4\\program\\startOpenoffice.bat";
System.out.println(commands);
//执行的命令:cmd.exe /C C:\Program Files (x86)\OpenOffice 4\program\startOpenoffice.bat
pro = Runtime.getRuntime().exec(commands);
connection = new SocketOpenOfficeConnection(soffice_host, Integer.parseInt(soffice_port));
System.out.println("获得连接"+connection);
//获得连接com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection@7002ee59
connection.connect();
startOpenoffice.bat:
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
错误信息:
获得连接com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection@7002ee59
09:07:58.807 [main] DEBUG c.a.j.o.c.SocketOpenOfficeConnection - connecting
java.net.ConnectException: connection failed: socket,host=127.0.0.1,port=8100,tcpNoDelay=1: java.net.ConnectException: Connection refused: connect
at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection.connect(AbstractOpenOfficeConnection.java:79)
at com.fdauto.preview.read.ToWord.doc2Html(ToWord.java:82)
at com.fdauto.preview.read.ToWord.main(ToWord.java:103)
手动敲命令:
cd C:\Program Files (x86)\OpenOffice 4\program
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
相关分类