2

In my Play application, I use Reflections ( http://code.google.com/p/reflections/ ) to get some fields annotated with a particular annotation.

Reflections requires to have access to the .class files to create its index. In DEV mode it works great since Play generates the .class files in tmp/classes . But in PROD mode, Play doesn't generate those .class files by default. And therefore my application just doesn't work!

Is there a way to force Play to generate the .class files, even in PROD mode?

electrotype
  • 8,342
  • 11
  • 59
  • 96
  • I found an ugly workaround: https://groups.google.com/d/msg/play-framework/ZkMvMMje46U/pucF0UTZ80QJ . I'm still interested by a better solution though! – electrotype Jan 05 '12 at 00:06

3 Answers3

2

You should try precompiling you code first using play precompile. Then launch your application with play start -Dprecompiled=true This should do the trick.

Alain
  • 385
  • 1
  • 3
  • 14
  • This actually works! In DEV mode, I tell Reflections to use "tmp/classes", and when deploying in PROD mode, I precompile first and then tell Reflections to use "precompiled/java" as the .class files source. Thanks! – electrotype Jan 05 '12 at 20:43
0

Another good solution would be to use Reflections to scan and save the metadata as XML once on compile time, and than on bootstrap time collect that XML and initialize Reflections without scanning.

If using Maven, You would first need to configure the plugin:

<plugin>
    <groupId>org.reflections</groupId>
    <artifactId>reflections-maven</artifactId>
    <version>0.9.8</version>
    <executions>
        <execution>
            <goals>
                <goal>reflections</goal>
            </goals>
            <phase>process-classes</phase>
        </execution>
    </executions>
</plugin>

And than on bootstrap:

Reflections reflections =
            isProduction() ? Reflections.collect() : new Reflections("your.package.here");

If not using Maven, you can do it programmatically. For more info, look at 'collect pre scanned metadata' in the Reflections UseCases Wiki

zapp
  • 1,533
  • 1
  • 14
  • 18
0

Have you checked your "precompiled" directory? When running in PROD mode, the class files are placed here.

  • Steve
Steve Chaloner
  • 8,162
  • 1
  • 22
  • 38
  • No "precompiled" folder is generated, even if I start the application using "-Dprecompiled=true". I think _you_ have to provide the compiled .class files to the application to use the "precompiled" option. This is not what I want! – electrotype Jan 05 '12 at 12:11