gpt4 book ai didi

javascript - Heroku 环境导致 Java/Nashorn/ReactJS 应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 06:45:14 24 4
gpt4 key购买 nike

Github 仓库 https://github.com/damorton/dropwizardheroku-webgateway

构建./gradlew阶段

Heroku 应用程序在构建和 webpack 阶段后使用 heroku local 在本地运行良好,但在 Heroku 环境中崩溃,因为应用程序无法读取由 Heroku 生成的 bundle.js 文件构建的 webpack 阶段。

到目前为止已完成

  • 使用 heroku run bash 登录 Heroku 应用程序,并检查是否已创建 bundle.js 文件,确实如此。
  • 更新了 system.properties 以使用与本地环境类似的 Java 版本 java.runtime.version=1.8.0_131

Heroku 日志

Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2017-05-05T10:55:43.963570+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
2017-05-05T10:55:45.617664+00:00 app[web.1]: INFO [2017-05-05 10:55:45,613] org.eclipse.jetty.util.log: Logging initialized @1649ms
2017-05-05T10:55:45.696063+00:00 app[web.1]: INFO [2017-05-05 10:55:45,695] io.dropwizard.server.SimpleServerFactory: Registering jersey handler with root path prefix: /
2017-05-05T10:55:45.696110+00:00 app[web.1]: INFO [2017-05-05 10:55:45,695] io.dropwizard.server.SimpleServerFactory: Registering admin handler with root path prefix: /admin
2017-05-05T10:55:45.696230+00:00 app[web.1]: INFO [2017-05-05 10:55:45,696] io.dropwizard.assets.AssetsBundle: Registering AssetBundle with name: assets for path /assets/*
2017-05-05T10:55:59.241010+00:00 app[web.1]: InputString in is null with path assets/js/bundle.js
2017-05-05T10:55:59.243502+00:00 app[web.1]: Exception in thread "main" java.lang.NullPointerException
2017-05-05T10:55:59.243739+00:00 app[web.1]: at java.io.Reader.<init>(Reader.java:78)
2017-05-05T10:55:59.243867+00:00 app[web.1]: at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
2017-05-05T10:55:59.243967+00:00 app[web.1]: at com.bitbosh.dropwizardheroku.webgateway.api.NashornController.read(NashornController.java:46)
2017-05-05T10:55:59.244023+00:00 app[web.1]: at com.bitbosh.dropwizardheroku.webgateway.api.NashornController.<init>(NashornController.java:27)
2017-05-05T10:55:59.244096+00:00 app[web.1]: at com.bitbosh.dropwizardheroku.webgateway.Main.run(Main.java:43)
2017-05-05T10:55:59.244149+00:00 app[web.1]: at com.bitbosh.dropwizardheroku.webgateway.Main.run(Main.java:23)
2017-05-05T10:55:59.244212+00:00 app[web.1]: at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43)
2017-05-05T10:55:59.244255+00:00 app[web.1]: at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:85)
2017-05-05T10:55:59.244306+00:00 app[web.1]: at io.dropwizard.cli.Cli.run(Cli.java:75)
2017-05-05T10:55:59.244391+00:00 app[web.1]: at io.dropwizard.Application.run(Application.java:79)
2017-05-05T10:55:59.244436+00:00 app[web.1]: at com.bitbosh.dropwizardheroku.webgateway.Main.main(Main.java:26)

从日志中,应用程序抛出 NullPointerException 这是由 NashornController.java 中的 Nashorn 引擎评估从 bundle.js 文件的 InputStream 创建的 Reader 引起的。

我不明白的是为什么它在本地工作正常,但在 Heroku 环境中崩溃。如果我不创建 bundle.js 文件并评估添加到 bundle 中的 Javascript 源代码,则一切正常。

最佳答案

问题

如果不使用 Spring Boot 或 Ratpack,Heroku 将运行 ./gradlew stage,这意味着开发人员需要在由运行的 stage 任务中指定构建期间发生的情况平台。 stage 所依赖的任务不按任何预定义的顺序运行。这会导致 webpack 任务在 installDist 之后运行,在 bundle.js 存在之前构建 Jar。

解决方案

定义任务运行的顺序。

task stage(dependsOn: ['installDist', 'webpack', 'npmInstall', 'clean'])
npmInstall.mustRunAfter clean
webpack.mustRunAfter npmInstall
installDist.mustRunAfter webpack

https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku#verify-that-your-build-file-is-set-up-correctly

关于javascript - Heroku 环境导致 Java/Nashorn/ReactJS 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43794366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com