1

我正在使用 Windows 10 上的阴影 jar 测试各种使用 Documents4j 的方法。我使用以下内容:

SERVER: documents4j-server-standalone-1.1.5-shaded.jar
Command Line: java -jar %~dp0documents4j-server-standalone-1.1.5-shaded.jar http://localhost:9998 -L%~dp0server-log.log -Vall 

CLIENT: documents4j-client-standalone-1.1.5-shaded.jar
Command Line: java -jar %~dp0documents4j-client-standalone-1.1.5-shaded.jar http://localhost:9998 -L%~dp0client-log.log -Vall

在客户端控制台中,我输入 0 和完整的文件路径,即C:\temp2\Sample.docx

然后显示此消息:预定转换:C:\temp2\Sample.docx -> C:\temp2\Sample.docx.txt

当独立服务器以登录用户身份启动时转换成功,但以管理员权限启动时失败(未生成转换文件)。

以下是日志摘录(附件):

客户端日志

Line 2220

FAILED [ADMINISTRATOR]
2021-04-03 13:39:02,731 WARN  [main] c.documents4j.standalone.StandaloneClient - Converter com.documents4j.job.RemoteConverter@475b7792 is not operational

SUCCESSFUL [USER]
2021-04-03 13:54:49,694 INFO  [main] c.documents4j.standalone.StandaloneClient - Converter com.documents4j.job.RemoteConverter@160c3ec1 is operational

服务器日志

LIne 303
FAILED [ADMINISTRATOR]
2021-04-03 13:39:01,862 TRACE [grizzly-http-server-0] c.d.c.msoffice.MicrosoftWordBridge - Execute no-argument script C:\Users\GRAEME~1.PTB\AppData\Local\Temp\1617419299961-0\word_assert1520023368.vbs
2021-04-03 13:39:01,862 DEBUG [grizzly-http-server-0] org.zeroturnaround.exec.ProcessExecutor - Executing [cmd, /S, /C, ""C:\Users\GRAEME~1.PTB\AppData\Local\Temp\1617419299961-0\word_assert1520023368.vbs""] in C:\Users\GRAEME~1.PTB\AppData\Local\Temp\1617419299961-0.
2021-04-03 13:39:01,872 DEBUG [grizzly-http-server-0] org.zeroturnaround.exec.ProcessExecutor - Started Process[pid=18600, exitValue="not exited"]
2021-04-03 13:39:01,873 TRACE [Thread-4] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@4e48de90 started.
2021-04-03 13:39:01,873 TRACE [Thread-5] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@786a36ca started.
2021-04-03 13:39:02,150 TRACE [Thread-4] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@4e48de90 finished.
2021-04-03 13:39:02,150 TRACE [Thread-5] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@786a36ca finished.
2021-04-03 13:39:02,153 DEBUG [WaitForProcess-Process[pid=18600, exitValue="not exited"]] org.zeroturnaround.exec.WaitForProcess - Process[pid=18600, exitValue=-6] stopped with exit code -6

SUCCESSFUL [USER]
2021-04-03 13:54:48,260 TRACE [grizzly-http-server-1] c.d.c.msoffice.MicrosoftWordBridge - Execute no-argument script C:\Users\GRAEME~1.PTB\AppData\Local\Temp\1617420258290-0\word_assert59744299.vbs
2021-04-03 13:54:48,261 DEBUG [grizzly-http-server-1] org.zeroturnaround.exec.ProcessExecutor - Executing [cmd, /S, /C, ""C:\Users\GRAEME~1.PTB\AppData\Local\Temp\1617420258290-0\word_assert59744299.vbs""] in C:\Users\GRAEME~1.PTB\AppData\Local\Temp\1617420258290-0.
2021-04-03 13:54:48,317 DEBUG [grizzly-http-server-1] org.zeroturnaround.exec.ProcessExecutor - Started Process[pid=1724, exitValue="not exited"]
2021-04-03 13:54:48,318 TRACE [Thread-5] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@11cbcb1c started.
2021-04-03 13:54:48,318 TRACE [Thread-4] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@2c99b36 started.
2021-04-03 13:54:48,750 TRACE [Thread-4] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@2c99b36 finished.
2021-04-03 13:54:48,750 TRACE [Thread-5] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@11cbcb1c finished.
2021-04-03 13:54:48,753 DEBUG [WaitForProcess-Process[pid=1724, exitValue="not exited"]] org.zeroturnaround.exec.WaitForProcess - Process[pid=1724, exitValue=3] stopped with exit code 3

此外,启动独立客户端时会出现这些警告:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/C:/documents4j/documents4j-server-standalone-1.1.5-shaded.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
4

2 回答 2

0

正如documents4j 文档中所指出的,您可能需要准备通常未设置为运行Word 的用户。正如文档中所说:

  1. 在 32 位系统上,创建文件夹 C:\Windows\System32\config\systemprofile\Desktop。在 64 位系统上,创建文件夹 C:\Windows\SysWOW64\config\systemprofile\Desktop。更多信息可以在 MSDN 上找到。
  2. 您可以操作 MS Window 的注册表,以便 MS Office 应用程序使用本地服务帐户以外的其他帐户运行。这种方法记录在 MSDN 上。请注意,这会破坏 MS Window 的沙盒模型,并对运行 MS Office 的机器造成额外的安全威胁。
于 2021-04-05T21:05:29.547 回答
0

谢谢拉斐尔 - 现在解决了!我回顾了那些信息,现在我明白发生了什么。要成功运行 Word/Excel 需要一个有效的用户配置文件 - 在我的情况下,它是安装 Word/Excel 的配置文件。Word/Excel 需要将临时文件写入 %USERPROFILE%\Local\Temp 的权限。当程序以管理员身份运行时,系统似乎尝试写入不存在的位置,或者系统没有对原始 %USERPROFILE%\Local\Temp 的权限。

除了documents4j 文档之外,还需要一个额外的步骤。

这在 Céderic Missinne 于 2018 年 10 月 10 日发表的关于此主题的较早帖子中进行了概述: 在 Server 2012 R2 中自动化 MS Word

Start - Run - mmc comexp.msc /32
Expand: Component Services –> Computers – My Computer – DCOM Config
Search for: Microsoft Word 97 –> 2003 Document
RMC – Properties – Go to tab: Identity Set from “The launching user” to “This user”.
Use a “local Administrator account” which has once signed in to the server machine and 
has opened Word at least once in an interactive desktop.

就我而言,我从“交互式用户”更改为“启动用户”。

StandaloneServer 然后在以管理员身份运行时成功运行。

这也解决了一个类似的问题,我使用 Apache Procrun 将 StandaloneServer 作为 Windows 服务运行!

再次感谢拉斐尔!

于 2021-04-05T22:36:21.533 回答