有人在 Heroku 上成功部署了 GWT 应用程序吗?
Heroku 最近开始支持 Java 应用程序。浏览文档,它似乎类似于 Java Servlet 标准。有谁知道 GWT 应用程序已成功部署在 Heroku 上的实例吗?如果可以,有什么限制吗?
Heroku recently began supporting Java apps. Looking through the docs, it seems to resemble the Java Servlet Standard. Does anyone know of an instance where a GWT app has been successfully deployed on Heroku? If so, are there any limitations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,我已经使用此处的 Java 入门说明成功进行了部署:
http://devcenter.heroku.com/articles/java
我使用带有 appassembler 插件的 Maven 项目方法,但添加了 gwt-maven-plugin 以在构建过程中编译 GWT 应用程序。
当您推送到 heroku 时,您会看到 GWT 编译进程在一个线程上运行,速度非常慢,但运行良好。
嵌入式 Jetty 实例配置为在 src/main/resources/static 的 /static 处提供静态资源,我在构建期间将编译的 GWT 应用程序复制到此位置,然后正常引用 .nocache.js。
您还想了解什么?
您有一个选择,要么将 GWT 应用程序的 Javascript 表示形式本地构建到您的 Maven 项目中,提交它并从您的应用程序中读取它,要么像我提到的那样通过 gwt-maven-plugin 在 Heroku 中生成它。
通过嵌入式 Jetty 从 jar 内的静态位置提供文件的代码在 Guice ServletModule 中是这样的:(
请参阅下面我的其他答案,了解更简单且更少 Guice 驱动的方法来执行此操作。)
还有一些其他技巧要让嵌入式 Jetty 与 guice-servlet 一起工作,请告诉我这是否还不够。
Yes, I've got a successful deployment using the getting started with Java instructions here:
http://devcenter.heroku.com/articles/java
I use the Maven project with appassembler plugin approach but added gwt-maven-plugin to compile a GWT app during the build.
When you push to heroku you see the GWT compile process running, on one thread only so quite slow but it works fine.
The embedded Jetty instance is configured to serve up static resources at /static from src/main/resources/static and I copy the compiled GWT app to this location during the build and then reference the .nocache.js as normal.
What else do you want to know?
You've got a choice, either build the Javascript representation of your GWT app locally into your Maven project, commit it and the read it from your app, or to generate it inside Heroku via the gwt-maven-plugin as I mentioned.
The code to serve up files from a static location inside your jar via embedded Jetty is something like this inside a Guice ServletModule:
(See my other answer below for a simpler and less Guice-driven way to do this.)
There's a few other tricks to getting embedded Jetty working with guice-servlet, let me know if this isn't enough.
当 GWT 尝试读取其序列化策略时,我对此的第一个回答结果出现了问题。最后我选择了一种更简单的方法,不太基于 Guice。我必须单步执行 Jetty 代码才能理解为什么
setBaseResource()
是正确的选择 - 从 Javadoc 中这并不是显而易见的。这是我的服务器类 - 带有 main() 方法的服务器类,您可以根据 Heroku 文档通过应用程序组装器插件将 Heroku 指向该服务器类。
AppConfig.java 是一个 GuiceServletContextListener。
然后,将静态资源放在
src/main/resources/static/
下。My first answer to this turned out to have problems when GWT tried to read its serialization policy. In the end I went for a simpler approach that was less Guice-based. I had to step through the Jetty code to understand why
setBaseResource()
was the way to go - it's not immediately obvious from the Javadoc.Here's my server class - the one with the main() method that you point Heroku at via your app-assembler plugin as per the Heroku docs.
AppConfig.java is a GuiceServletContextListener.
You then put your static resources under
src/main/resources/static/
.理论上,人们应该能够使用 Jetty 或 Tomcat 的嵌入式版本运行 GWT,并在
main
中引导服务器,如 Heroku Java 文档中所述。In theory, one should be able to run GWT using the embedded versions of Jetty or Tomcat, and bootstrap the server in
main
as described in the Heroku Java docs.