5

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?

Tahir Akhtar
  • 11,385
  • 7
  • 42
  • 69

4 Answers4

2

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

Pere Villega
  • 16,429
  • 5
  • 63
  • 100
  • @PereVillega heroku is probably using a custom play script, since the original one will pass -javaagent as an application parameter, instead of as a JVM parameter. Anyway, I'm glad to know that New Relic agent is working with Play 2.0. :-) – marcospereira Jun 18 '12 at 04:09
2

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.

Zapodot
  • 462
  • 5
  • 10
2

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).


Jay Taylor
  • 13,185
  • 11
  • 60
  • 85
1

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.

Codemwnci
  • 54,176
  • 10
  • 96
  • 129
  • I've already tried `play -javaagent` followed by `run` on the console without luck. I agree that the solution probably lies in passing an appropriate parameter to SBT but google isn't helping me here :( – Tahir Akhtar Jun 13 '12 at 12:18