Reputation: 6279
I have two Play 2.2.1 applications, X and Y. Both of these applications have a Global object in the default package that extends GlobalSettings and overrides onStart. Application X is published in a maven repo and application Y has X as a dependency. When attempting to run application Y, I keep getting strange exceptions during onStart. These exceptions are getting thrown by code in application X's onStart function. I did not get any compile-time errors or warnings.
Is this expected? Is this a Play specific issue or would this happen any time names in the default package conflict like this? How can I prevent the GlobalSettings of the apps from mixing together?
I had originally put the common code into its own project that the two Play app's shared as a dependency. This was annoying to maintain and all of the shared code really belonged to app X, so I reorganized.
Upvotes: 0
Views: 141
Reputation: 12850
The errors you're seeing would stem from the fact that you have multiple Global
objects in your classloader, and which one is loaded is undefined. The classloader is like a filesystem, you can only have one file with a given name in a given directory. If you have two libraries on your classpath that define a file with the same name in the same directory, they don't combine, rather one overrides the other, and which one gets used depends on classloader implementations - in Play we specifically don't define the ordering.
The Global
object must only be defined by end applications. Any project that is intended to be consumed as a dependency must not define a Global
object. It should rather define the behaviour somewhere that can be consumed by a Global
object. If it wants to transparently plugin behaviour on start, consider implementing the Plugin
interface instead, as documented here:
http://developer.vz.net/2012/03/16/writing-a-play-2-0-module/
Upvotes: 1