0

In my application I use an annotation to mark some methods that I want to be executed during the "onStart" hook of my application. My code is like this:

@Override
public void onStart(Application app) {
    Reflections reflections = new Reflections("", new SubTypesScanner(false), new MethodAnnotationsScanner(), app.classloader()); //also tried without classloader
    Set<Method> onStartMethods = reflections.getMethodsAnnotatedWith(OnStart.class); //OnStart is my annotation

    if (CollectionUtils.isNotEmpty(onStartMethods)) {
        for (Method osm : onStartMethods) {
            // execute the methods
        }
    } else {
        // I CRASH the server because this is not a behaviour I want
    }

}

One point this work FLAWLESSLY both using play run, play start but it does not work any more if I use play dist. The error occurs both on our test server (EC2 ubuntu 13.10) and on my dev maching (Ubuntu 14.04LTS).

I use this to test on my machine.

$alias testdeploy
alias testdeploy='play compile && play dist && unzip -o target/universal/*.zip -d ~/test-deploy/ && bash ~/test-deploy/server_crm-1.0/bin/server_crm'

I am using Java7 with Play! 2.2. I am in need of some insight. What is happening ... and most of all how can I fix this?

UPDATE : Of course I tested play stage too ... same result as dist

le-doude
  • 3,345
  • 2
  • 25
  • 55

1 Answers1

1

Initiating Reflections with "" effectively scan urls obtained from ClasspathHelper.forPackage("").

You would probably want to examine in runtime those urls in your different deployment environments and use the correct parameter instead of "".

Otherwise use the other ClasspathHelper.forXXX to get the correct urls.

zapp
  • 1,533
  • 1
  • 14
  • 18