8
votes

Recently, we convert a tomcat/spring app to spring boot. Everything is working fine apart from new relic. Is there a way I can easily config new relic with spring boot project. I don't want to hard code the location of new relic agent jar path, then run the spring boot project with the path.

edit: Spring boot project is with maven

2
You may find this link useful: jdpgrailsdev.github.io/blog/2014/04/08/… This person is using Gradle instead of Maven, but he seems to have solved a similar problem, that is how to pass the new relic agent jar path to spring boot without hardcoding it.Nočnica
Thanks Toby_New_Relic. I saw this post before, but still can not figure out how to config with mavenjasonfungsing

2 Answers

10
votes

You can include NewRelic Maven dependency and use maven-dependency-plugin to unpack in into your target/classes directory, which allows Maven to include it into final Jar file. Then you have to add Premain-Class attribute into manifest file and you can use your application jar as -javaagent source. You can find details on my blog post

7
votes

Step by step instructions

  • Extract the files from the newrelic java agent archive.
  • Create a directory named newrelic in the root of your application.
  • Place the newrelic.jar from the archive in the above created newrelic folder
  • Place the newrelic.yml YAML config file in the above created newrelic folder.
  • Update the values in newrelic.yml as below.
    • license_key: 'your license key'
    • app_name: ‘Your application name’
  • Run you application by using the option javaagent
    • java -javaagent:newrelic\newrelic.jar -jar yourapplication.jar

-javaagent option needs to be before the -jar so the agent can start