前段时间因为要爬取淘宝店铺商品相关信息,所以决定使用JxBrowser进行抓取,但是在Mac环境开发完成后在部署到服务器上运行时却遇到了问题。
参考官方:https://jxbrowser-support.teamdev.com/docs/guides/x-server-in-headless-linux.html,执行:sudo apt-get install xvfb
安装Xvfb,然后执行:Xvfb :1 -screen 0 800x600x16
启动Xvfb,然后执行:xvfb-run java -jar yourApplication.jar
时却出现了如下的一堆报错信息。
03:15:50 SEVERE: There are next missing dependencies:
browsercore64 => libgtk-3.so.0, libgdk-3.so.0, libpangocairo-1.0.so.0, libpango-1.0.so.0, libatk-1.0.so.0, libcairo.so.2, libgdk_pixbuf-2.0.so.0, libnss3.so, libnssutil3.so, libsmime3.so, libnspr4.so, libXcomposite.so.1, libXcursor.so.1, libXi.so.6, libXrender.so.1, libXtst.so.6, libXss.so.1, libXrandr.so.2, libcups.so.2, libasound.so.2, libatk-bridge-2.0.so.0
libbrowsercore64.so => libgtk-3.so.0, libgdk-3.so.0, libpangocairo-1.0.so.0, libpango-1.0.so.0, libatk-1.0.so.0, libcairo.so.2, libgdk_pixbuf-2.0.so.0, libnss3.so, libnssutil3.so, libsmime3.so, libnspr4.so, libXcomposite.so.1, libXcursor.so.1, libXi.so.6, libXrender.so.1, libXtst.so.6, libXss.so.1, libXrandr.so.2, libcups.so.2, libasound.so.2, libatk-bridge-2.0.so.0
03:15:50 SEVERE: Failed to start IPC process.
java.lang.IllegalStateException: Missing dependendecies have been detected. Check the log for details.
at com.teamdev.jxbrowser.chromium.internal.ipc.ExternalChromiumProcessLinux.preProcessRun(SourceFile:2154)
at com.teamdev.jxbrowser.chromium.internal.ipc.ExternalChromiumProcess.doStart(SourceFile:64)
at com.teamdev.jxbrowser.chromium.internal.ipc.ChromiumProcess.start(SourceFile:241)
at com.teamdev.jxbrowser.chromium.internal.ipc.d.run(SourceFile:200)
at java.lang.Thread.run(Thread.java:748)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: com.teamdev.jxbrowser.chromium.BrowserException: IPC startup failure.
at com.teamdev.jxbrowser.chromium.Browser.<init>(SourceFile:414)
at com.teamdev.jxbrowser.chromium.Browser.<init>(SourceFile:357)
at com.teamdev.jxbrowser.chromium.Browser.<init>(SourceFile:318)
at com.example.jxb.JxbApplication.main(JxbApplication.java:86)
... 8 more
Caused by: com.teamdev.jxbrowser.chromium.internal.ipc.IPCException: Failed to start IPC process.
at com.teamdev.jxbrowser.chromium.internal.ipc.d.run(SourceFile:210)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Missing dependendecies have been detected. Check the log for details.
at com.teamdev.jxbrowser.chromium.internal.ipc.ExternalChromiumProcessLinux.preProcessRun(SourceFile:2154)
at com.teamdev.jxbrowser.chromium.internal.ipc.ExternalChromiumProcess.doStart(SourceFile:64)
at com.teamdev.jxbrowser.chromium.internal.ipc.ChromiumProcess.start(SourceFile:241)
at com.teamdev.jxbrowser.chromium.internal.ipc.d.run(SourceFile:200)
... 1 more
从上面报错信息中可以看出是因为缺少依赖而导致启动异常。一通谷歌之后最后确定只需要执行:apt -y install xvfb libxss1 libnss3 firefox
,然后再运行:xvfb-run java -jar yourApplication.jar
就可以正常启动了。
未经允许不得转载:鹞之神乐 » Ubuntu Server 18.04.4 LTS + Xvfb + JxBrowser 6.24.3