Is it possible to run Play Framework 2.0 server with a javaagent?

不羁岁月 提交于 2019-12-01 05:31:13

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


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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!