简体   繁体   English

playframework 1.2.x如何在开发模式下每次重载游戏时调用我的方法?

[英]playframework 1.2.x How to have my method call every time play reloads in dev mode?

I need a method to be called every time play reloads so I can use the new classes to rescan some stuff. 我需要在每次重装游戏时都调用一个方法,以便可以使用新类重新扫描某些内容。 How can I get that without developing a full blown plugin? 不开发完整的插件怎么办? ( I really just want to add something quick to my application and move on). (我真的只想向我的应用程序中快速添加一些内容并继续前进)。

On a side note, is there any good tutorial on doing a play plugin? 附带说明一下,有没有关于制作播放插件的好教程?

thanks, Dean 谢谢,院长

Every time your application reloads (which may be often in Dev mode), the @onApplicationStart methods are called. 每次您的应用程序重新加载时(通常在开发模式下),都会调用@onApplicationStart方法。

Therefore, just create a bootstrap job, using @onApplicationStart and you will achieve what you need. 因此,只需使用@onApplicationStart创建引导作业,即可实现所需的功能。

You can see more on this, by looking at the Play documentation for bootstrap jobs - http://www.playframework.org/documentation/1.2.5/jobs#concepts 您可以通过查看有关引导作业的Play文档了解更多信息-http: //www.playframework.org/documentation/1.2.5/jobs#concepts

Well, if you have any method that is run alot like NoSql.em(), and NoSql is in another jar file, it will not be in the Play.classloader and in that method, I finally do a Play.classloader.getAnnotatedResources() which gives me a List and I keep comparing the first one and when it changes, I know play reloaded. 好吧,如果您有很多像NoSql.em()这样运行的方法,并且NoSql在另一个jar文件中,则它将不在Play.classloader中,在该方法中,我最终会执行Play.classloader.getAnnotatedResources( ),这给了我一个列表,我一直在比较第一个列表,当列表更改时,我知道重新加载了播放。 For now, this sort of hack worked for me and the nosql layer stays up constantly with the in-memory nosql database now. 现在,这种破解对我有用,并且nosql层现在与内存中的nosql数据库保持一致。

While @OnApplicationStart is NOT called "every" single time play reloads, you can use the above method to know when it does reload 100% of the time instead of 75% of the time which is about the case of using @OnApplicationStart. 虽然@OnApplicationStart不被称为“每次”单次重装,但您可以使用上述方法来知道何时重装100%的时间,而不是使用@OnApplicationStart的75%的时间。

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

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