0

编辑:解决方案是将所有 phatomJS 相关脚本放入 Scripts 目录,并确保所有项目都不是 Windows 只读的。我的脚本和 phantomjs.exe 都存在这里:C:\jetty-distribution-9.0.0.M3\webapps\ROOT\Scripts\phantomjs.

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/'

编辑: 有没有人有一个在 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具有相同结果的值的其他变体:

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但是看着码头的输出,我被以下内容淹没了:

        [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...
4

2 回答 2

5

您收到 Beancreation 异常,因为 @PostConstruct afterBeanInit 方法失败。

当您将 app.properties 文件中的“脚本”属性留空时,它会尝试使用 ClassLoader 加载 highcharts-convert 文件。见这里

如 app.properties 文件中所述,这仅在 Tomcat 中进行了测试。显然,这对 Jetty 来说不是开箱即用的。可能是因为 ClassLoader 不同,又或者你不得不将应用程序部署为一场爆炸式的战争?

但最简单的方法是在 app.properties 文件中指定“脚本”属性。请注意,highcharts-convert.js 脚本使用的强制文件也必须存在于同一文件夹中。

我在带有 Jetty 的 windows 下使用的属性文件的代码示例。

#### 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

并将war文件复制到Jetty webapps文件夹。它奏效了。

于 2013-05-24T14:59:17.397 回答
0

上面的第一个示例表明您正在配置指向码头 9.0.0.M3(9.0.3.v20130506 是最新的),但您的第二个示例显示您使用 jetty-maven-plugin 8.1.2(8.1.10.v20130312 是最新)它不使用任何码头分布,它使用一个嵌入式码头实例,它连接起来并通过 maven 插件启动。

您需要决定如何运行码头,通过发行版(您的第一个示例)或通过 maven 插件(org.eclipse.jetty:jetty-maven-plugin:9.0.3.v20130506 可能是您应该使用的一个) 并相应地配置您的 'exec =' 属性。

于 2013-05-21T14:27:45.600 回答