Question

I would like to be able to run the Play Framework 2.0 server with a javaagent.

Some resources on the web (see here and here ) suggest that this could be done simply by appending -javaagent:/path/to/agent.jar to play run but it doesn't seems to work for me.

Any clues?

Was it helpful?

Solution

There is no clean way to pass the -javaagent parameter to the java command invocation with play 2.0.1-2.0.4 without modifying a script.

I was able to get a javaagent working using the following technique:

# Modify the play/framework/build script to include an extra environment variable
sed -i 's/^java\( \${PLAY_OPTS}\)\?/java ${PLAY_OPTS}/' ${playPath}/framework/build

Then it is possible to pass the -javaagent param like this:

export PLAY_OPTS='-javaagent:/lib/newrelic/newrelic.jar'

${playPath}/play -Dconfig.file=conf/prod.conf -Dlogger.file=conf/prod-logger.xml start


Update

An unfortunate sidenote- I just found out from New-Relic support that New-Relic definitely does not support play-framework 2.x right now (2012-10-04).


OTHER TIPS

I'm using it in Heroku, working fine like follows (in my Procfile):

  play ${JAVA_OPTS} ${MYCONFIG} -javaagent:/newrelic/newrelic.jar run

My newrelic folder is on root, same level as app

The java command line for SBT is defined in the "build.bat" batch file (Win) or "build" shell script (U*X) located in the %PLAY2_HOME%/framework folder

You can add a javagent or tweak other JVM settings used by SBT/Play2 by adjusting the parameters defined there. This is probably what the clever people at Heroku has already done.

The reason why the examples don't work, is because the examples are for Play 1.x, and you are using play 2.x. Play 1.x uses Java (via python scripts) where as Play 2 uses SBT.

You need to configure SBT. I am not an SBT expert, but from Googling, I would have thought simply running

play -javaagent:/path/to/agent.jar

and then followed by run once the console had started should do the trick, but if that doesn't work, then it is a case of finding out how to add the javaagent syntax to the SBT console.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top