`
pudding811
  • 浏览: 3459 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

Grails on google App engine第二天

阅读更多
经过第一天的部署,小有成就(原谅我吧,就是这么容易满足).接下来就是考虑做个什么应用,大的应用没时间(能力也有限),小的应用也没什么意思,最后决定做一个个人站点(非常没创意...)

简单说下我的想法(只是想法,一切都没实现之前只是愿景)
最重要的模块个人的blog的发布系统(和普通的blog没什么两样):发表blog,留言,查看blog;后续的可能会加上一些小应用,例如:twitter,flickr,rss订阅,利用google的api尽可能多的集成(当然包括Google AdSense),顺便吼下google很好很强大(被拖走...),很期待9月份(听说,听说)将要推出的googl wave,本人申请了wave但是不够幸运。哇,扯了这么多没用的。

正文:在部署成功之后,马上想到的就是测试连接数据库,google采用的是App Engine 数据存储区,为java提供了两种接口jdo和jpa,因为google提供的文档偏重讲解了jdo,所以就选了jdo。

1.创建domain

在grails中安装完app-engine插件之后
grails create-domain-class account创建的领域类中默认创建了两个属性id和property1
import javax.jdo.annotations.*;
// import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
class Account{

	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	Long id

	@Persistent
	String property1

    static constraints = {
    	id( visible:false)
	}
}


2.创建controller和view
google app-engine可以在本地建立存储区进行测试(一直不明白这个存储区到底是个什么东西),所以不用上传测试,直接在本地测试
grails generate-all account

3.启动app
grails app-engine run
启动之后在创建account的时候总是失败(后台没有报错)
经查原来grails自动创建的AccountController中发现了try了之后没有catch
def save = {
        def accountInstance = new Account(params)
		if(!accountInstance.hasErrors() ) {
			try{
				println "before storing id is ${accountInstance.id}"
				persistenceManager.makePersistent(accountInstance)
				println "after storing id is ${accountInstance.id}"
			}catch(e){  //手动加入catch
				println "exception!!!!!!!!!: $e"
				} 
			finally{
				flash.message = "Account ${accountInstance.id} created"
				redirect(action:show,id:accountInstance.id)	
			}
		}

打印出来的异常:
org.datanucleus.jdo.exceptions.ClassNotPersistenceCapableException: 
The class "The class "Account" is not persistable. 
This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found." is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data for the class is not found.
 [java] NestedThrowables:
 [java] org.datanucleus.exceptions.ClassNotPersistableException: 
The class "Account" is not persistable. 
This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.

凭借我拙略的英文异常提到了3点:
1.account没有被“增强”  //这个不可能 @Persistent注释就已经完成增强
2.classpath的问题    //我也将app的jar加入到了classpath 见Grails on google App engine开始
3.没发现注释  // 和第一条差不多


3.解决
貌似结果是没有发现domain account或者增强account出的问题,但是我都是按照手册来的啊,又检查了配置也没有问题,奇怪。
我google搜啊搜啊都没有找到解决办法(要不是用grails创建app的人不多,要不就是这个问题很低级),没办法,只有给一个国外做例子的作者发了邮件(不过我发现他很有可能不是外国人,至少不是美国人,因为他在北京时间18点左右给我回的邮件,哪个鬼会在早上六点一起来就看邮件,至少程序员不会)
他给我回的邮件很简单:

You domain class needs to be in a package when using app-engine. Please post questions to the mailing list or nabble forums

恩,domain应该在package中。
(让我发邮件至少得告诉我邮箱,至少论坛中没有,nabble论坛?算了吧,英文不过关,不丢人去了)
随后我将account加入到了一个package中,而且将对应的controller也建立了相应的package,并将accountController放入其中(经测试这是必须的)。

令人惊喜的结果--成功了。

还有两点需要说明:
命令行的方式ctrl+c并不能结束grails的运行,还要在任务管理器中手动结束掉java进程不知道*-nix怎么样,也可能是grails就这么设计的。
在grails app-engin run的最后一步非常的慢,最后找到是因为瑞星的监控,关闭之后就很快了
我的环境是windows powerCmd ue
分享到:
评论
1 楼 dldahua 2010-04-08  
我也遇到了相同的情况,但怎么改都不行啊,我用的是struts2的mvc模式,还望指教

相关推荐

Global site tag (gtag.js) - Google Analytics