Reputation: 20204
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
Upvotes: 0
Views: 304
Reputation: 20204
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. For now, this sort of hack worked for me and the nosql layer stays up constantly with the in-memory nosql database now.
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.
Upvotes: 1
Reputation: 54914
Every time your application reloads (which may be often in Dev mode), the @onApplicationStart methods are called.
Therefore, just create a bootstrap job, using @onApplicationStart and you will achieve what you need.
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
Upvotes: 2