开发者

Using GWT with a database

How can I configure the embedded Jetty that comes with GWT so that when I c开发者_如何学编程lick the run button in Eclipse, my server application can access a postgresql database?


We had some luck with porting our Tomcat web application (that uses OpenEJB) to GWT embedded server (Jetty) by just following standard procedures for configuring web application.

But after all we decided for running in hosted mode with noserver option and connecting to Tomcat server instead.


Yah, the GWT embedded Jetty server works ok for simple servlets, but most of the time you be needing something more that Jetty doesn't offer. Other than the simple test servlets I always use the GlassFish and Tomcat container with the noserver option. This allow your servlets to utilize the full power of Java Enterprise Bean and Java Persistence API (JPA). The easiest way for you to test out would be build the project and deploy the WAR to container. Then modify your GWT project ant target hosted to use the noserver option and pass the -startupUrl option with your Tomcat/Glassfish's URL(you project's URL on the container). The GWT can be very lean when combined with pure JPA using POJO DTO. See my GWTPersistence example at > NingZhang.info


Turned out that what I needed to do was to run the app on a Tomcat server on a different host (because the database I needed was too hard to bring over to the development machine for testing). I ended up using "ant war && scp Navaid.war foo:/www/tomcat/webapps/" to deploy the server side, and I modified the Eclipse run configuration for the project to

  • unclick the "Run built-in server" on the "Main" tab
  • add the following options to "Program Arguments" on the "Arguments" tab

    -noserver -whitelist "^http[:][/][/]foo[.]bar[.]com[:]8080"

I also managed to modify build.xml so that "ant hosted" will run the hosted mode with the remote server. I found the "hosted" target, and the <arg> line that looks like:

<arg value="-startupUrl"/>

and added the following line before it:

<arg value="-noserver"/>

and changed the line after it from

<arg value="Navaid.html"/>

to

<arg value="http://foo.bar.com:8080/Navaid/Navaid.html"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜