编辑: 解决方案是将所有与phatomJS相关的脚本放入Scripts目录中,并确保所有项目都不是Windows只读的。我的脚本和phantomjs.exe都在这里存在:C:\jetty- distribution-9.0.0.M3\webapps\ROOT\Scripts\phantomjs。
C:\jetty- distribution-9.0.0.M3\webapps\ROOT\Scripts\phantomjs
该app.properties文件具有以下配置:
app.properties
# location of the phantomjs executable, could be for example /usr/local/bin/phantomjs exec = C:/jetty-distribution-9.0.0.M3/webapps/ROOT/Scripts/phantomjs/phantomjs.exe # location of convert script used by phantomjs, optional to leave the script property empty, than it's using the script located in: /WEB-INF/phantomjs/highcharts-convert.js. This is tested in TOMCAT, but specify a path if resource loading isn't working with the classloader (f.e. with Jetty server), script = a/path/to/my/phantomjs-script.js script = C:/jetty-distribution-9.0.0.M3/webapps/ROOT/Scripts/phantomjs/highcharts-convert.js
我现在可以通过此处加载的演示导出http://localhost:8080/highcharts- export/demo,也可以通过使用我们的网站来调用它url: 'http://localhost:8080/highcharts-export/'
http://localhost:8080/highcharts- export/demo
url: 'http://localhost:8080/highcharts-export/'
编辑: 有没有人在Windows和Jetty下获得可工作的app.properties文件?
通过对app.properties进行此修改,我已经解决了下面列出的一些问题:
# location of the phantomjs executable, could be for example /usr/local/bin/phantomjs exec = "C:\\jetty-distribution-9.0.0.M3\\webapps\\ROOT\\Scripts\\phantomjs\\phantomjs.exe" # location of convert script used by phantomjs, optional to leave the script property empty, than it's using the script located in: /WEB-INF/phantomjs/highcharts-convert.js. This is tested in TOMCAT, but specify a path if resource loading isn't working with the classloader (f.e. with Jetty server), script = a/path/to/my/phantomjs-script.js script = /WEB-INF/phantomjs/highcharts-convert.js
该exec值的其他变体具有相同的结果:
exec
C:\\jetty-distribution-9.0.0.M3\\webapps\\ROOT\\Scripts\\phantomjs\\phantomjs.exe C:/jetty-distribution-9.0.0.M3/webapps/ROOT/Scripts/phantomjs/phantomjs.exe C:\jetty-distribution-9.0.0.M3\webapps\ROOT\Scripts\phantomjs\phantomjs.exe
现在,我可以开始演示,http://localhost:8080/highcharts-export/demo但看着码头的输出,我到处都是:
http://localhost:8080/highcharts-export/demo
[ERROR] [pool-1-thread-1 02:55:19] (TaskUtils.java:handleError:95) Unexpected error occurred in sche duled task. java.lang.RuntimeException: Error, PhantomJS couldnot start at com.highcharts.export.server.Server.<init>(Server.java:56) at com.highcharts.export.pool.ServerObjectFactory.create(ServerObjectFactory.java:36) at com.highcharts.export.pool.ServerObjectFactory.create(ServerObjectFactory.java:14) at com.highcharts.export.pool.AbstractPool.createObject(AbstractPool.java:26) at com.highcharts.export.pool.AbstractPool.poolCleaner(AbstractPool.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnabl e.java:64) at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErro rHandlingRunnable.java:53) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source) at java.util.concurrent.FutureTask.runAndReset(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown S ource) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
以下 是 原始问题: 这是此问题的后续措施。现在,我可以成功(至少根据maven的要求)构建最新的highcharts- export服务器。我只修改了app.properties文件,如下所示:
# location of the phantomjs executable, could be for example /usr/local/bin/phantomjs exec = C:/jetty-distribution-9.0.0.M3/webapps/ROOT/Scripts/phantomjs
无论phatomjs的位置如何配置,我都会收到以下错误。
但是,当我将其加载到码头时,出现以下错误,并且无法解决此问题。
C:\hc-exporter>mvn jetty:run [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.highcharts.expor t:highcharts-export:war:2.0.1 [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-eclipse-plugin is missin g. @ line 150, column 12 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed pro jects. [WARNING] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building highcharts-export 2.0.1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> jetty-maven-plugin:8.1.2.v20120308:run (default-cli) @ highcharts-export >>> [INFO] [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ highcharts-export --- [debug] execute contextualize [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ highcharts-export --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ highcharts-export --- [debug] execute contextualize [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\hc-exporter\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ highcharts-export --- [INFO] No sources to compile [INFO] [INFO] <<< jetty-maven-plugin:8.1.2.v20120308:run (default-cli) @ highcharts-export <<< [INFO] [INFO] --- jetty-maven-plugin:8.1.2.v20120308:run (default-cli) @ highcharts-export --- [INFO] Configuring Jetty for project: highcharts-export [INFO] webAppSourceDirectory C:\hc-exporter\src\main\webapp does not exist. Defaulting to C:\hc-expo rter\src\main\webapp [INFO] Reload Mechanic: manual [INFO] Classes = C:\hc-exporter\target\classes [INFO] Added extra scan target:C:\hc-exporter\src\main\webapp\WEB-INF\pages [INFO] Added extra scan target:C:\hc-exporter\src\main\webapp\resources [INFO] Context path = /export [INFO] Tmp directory = C:\hc-exporter\target\tmp [INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml [INFO] Web overrides = none [INFO] web.xml file = file:/C:/hc-exporter/src/main/webapp/WEB-INF/web.xml [INFO] Webapp directory = C:\hc-exporter\src\main\webapp 2013-05-21 09:00:07.656:INFO:oejs.Server:jetty-8.1.2.v20120308 2013-05-21 09:00:07.987:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp r equires one, please configure one. 2013-05-21 09:00:09.162:INFO:/export:No Spring WebApplicationInitializer types detected on classpath 2013-05-21 09:00:09.477:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/export,file:/C :/hc-exporter/src/main/webapp/},file:/C:/hc-exporter/src/main/webapp/ 2013-05-21 09:00:09.478:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/export,file:/C :/hc-exporter/src/main/webapp/},file:/C:/hc-exporter/src/main/webapp/ 2013-05-21 09:00:09.482:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/export,file:/C :/hc-exporter/src/main/webapp/},file:/C:/hc-exporter/src/main/webapp/ 2013-05-21 09:00:09.532:INFO:/export:Initializing Spring root WebApplicationContext [ERROR] [main 09:00:10] (ContextLoader.java:initWebApplicationContext:307) Context initialization fa iled org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverObject Factory': Invocation of init method failed; nested exception is java.lang.NullPointerException at...
您正在获取Beancreation异常,因为@PostConstruct afterBeanInit方法失败。
当您将app.properties文件中的’script’属性保留为空时,它将尝试使用ClassLoader加载highcharts- convert文件。看这里。
如app.properties文件中所述,这仅在Tomcat中进行了测试。显然,这对于Jetty来说不是开箱即用的。也许是因为ClassLoader是不同的,还是您不得不将应用程序部署成爆炸式战争?
但是简单的方法是在app.properties文件中指定’script’属性。请注意,highcharts- convert.js脚本使用的强制性文件也必须存在于同一文件夹中。
属性文件的代码样本,我在Windows下使用Jetty使用。
#### phantomjs properties #### # the host and port phantomjs listens to host = 127.0.0.1 port = 7777 # location of the phantomjs executable, could be for example /usr/local/bin/phantomjs exec = phantomjs # location of convert script used by phantomjs, optional to leave the script property empty, than it's using the script located in: /WEB-INF/phantomjs/highcharts-convert.js. This is tested in TOMCAT, but specify a path if resource loading isn't working with the classloader (f.e. with Jetty server), script = a/path/to/my/phantomjs-script.js script = C:/Users/gert/SRC/highcharts.com/exporting-server/java/highcharts-export/target/highcharts-export/WEB-INF/phantomjs/highcharts-convert.js
更改app.properties文件后,我将与 mvn clean package
mvn clean package
并将war文件复制到Jetty webapps文件夹。而且有效。