简体   繁体   English

带有可选Google App Engine支持的标准Java Webapp

[英]Standard Java webapp with optional Google App Engine support

I've built plenty of Java webapps that run in standard containers like Tomcat and Jetty, but I've never built one that runs in Google's App Engine before. 我已经构建了许多可在诸如Tomcat和Jetty之类的标准容器中运行的Java Web应用程序,但是我之前从未构建过可在Google App Engine中运行的Java Web应用程序。 I'm using Maven, so I had originally thought that I could just do this with build profiles to just optionally include Google's libraries at build time to make an App Engine-compatible WAR. 我使用的是Maven,因此我本来以为我可以通过构建配置文件来做到这一点,以便在构建时选择包含Google的库,以制作兼容App Engine的WAR。

Unfortunately, it seems to be more complex than that. 不幸的是,它似乎比这更复杂。 In reading through the documentation, there seems to be an awful lot of very specific code you have to write in order to use the App Engine. 阅读文档时,您似乎必须编写很多非常特定的代码才能使用App Engine。 For example, all file system writes need to go through the App Engine data store, so you can't use native java.io.* libraries. 例如,所有文件系统写操作都需要通过App Engine数据存储区进行,因此您不能使用本机java.io.*库。

I understand why these things are necessary, and I wouldn't mind having some of this code in my webapp. 我理解为什么这些事情是必要的,并且我不介意在我的webapp中包含一些代码。 However, I really don't like the idea that my webapp can only run on the App Engine. 但是,我真的不喜欢我的Web应用程序只能在App Engine上运行的想法。 Is it possible/feasible to write my code in such a way that I can also run it in a typical container like Tomcat? 是否可以/也可以在像Tomcat这样的典型容器中运行代码的方式来编写代码?

It mostly depends on what you app is going to do. 这主要取决于您的应用程序将要执行的操作。 You are going to run into troubles as soon as you want to do stuff with the datastore, or caching for example. 您想要对数据存储或缓存进行处理时,就会遇到麻烦。 Perhaps you could wrap things line datastore calls or caching, but certain apis, like search you can forget about. 也许您可以将数据包装到数据存储区调用或缓存中,但是某些api(例如搜索)可能会忘记。 If you just want to run something locally that is no problem you can mock the app engine locally. 如果您只想在本地运行某些东西,则可以在本地模拟应用程序引擎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM