intellij-ideaclasspath

intellij run configuration: how to you add -javaagent:target/newrelic/newrelic.jar BEFORE the main class?


In intellij, you have to setup a run configuration to be able to run an app.

In the run config, you specify the jdk, then -cp [your module], then the main class, then you can add "-javaagent:target/newrelic/newrelic.jar" in "program arguments"

The problem is, this puts -javaagent:target/newrelic/newrelic.jar at the end of the command line, and doesnt work. It needs to come before the main class, and produces a command line like this:

"C:\Program Files\Zulu\zulu-8\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1.1\lib\idea_rt.jar=61424:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1.1\bin" -Dfile.encoding=UTF-8 -classpath "... thousands of classes .." com.myorg.myapp.Main -javaagent:target/newrelic/newrelic.jar

We assume that new relic is not working because the agent is happening at the end, or maybe because -javaagent is already in there?


Solution

  • Go to Edit Configurations -> Modify Options -> Add VM Options:

    javaagentconfiguration

    Put the full path of the javaagent for new relic, newrelic.jar file. Make sure that your newrelic.yml file is in the same folder that the newrelic.jar file.

    then run your spring app and it will use new relic agent: Running app