Pablo Fernandez
Pablo Fernandez

Reputation: 287460

Why is Heroku attempting to run newrelic-agent.jar instead of my app?

My app was working, it's working in staging, but after pushing that build to production, Heroku is running this command:

java -Dserver.port=12366 -javaagent:target/newrelic-agent.jar -jar target/newrelic-agent.jar

Why is Heroku trying to run newrelic-agent.jar instead of my app's jar?

My build log looks like this:

-----> Java app detected
-----> Installing JDK 1.8... done
-----> Installing Maven 3.3.9... done
-----> Executing: mvn -DskipTests clean dependency:list install
       [INFO] Scanning for projects...
       [INFO]                                                                         
       [INFO] ------------------------------------------------------------------------
       [INFO] Building projectxserver 1.0.0-SNAPSHOT
       [INFO] ------------------------------------------------------------------------
       [WARNING] The artifact org.hibernate:hibernate-validator:jar:6.0.9.Final has been relocated to org.hibernate.validator:hibernate-validator:jar:6.0.9.Final
       [INFO] 
       [INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ projectxserver ---
       [INFO] 
       [INFO] --- maven-dependency-plugin:3.0.2:list (default-cli) @ projectxserver ---
       [INFO] 
       [INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ projectxserver ---
       [INFO] Using 'UTF-8' encoding to copy filtered resources.
       [INFO] Copying 1 resource
       [INFO] Copying 11 resources
       [INFO] 
       [INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ projectxserver ---
       [INFO] Changes detected - recompiling the module!
       [INFO] Compiling 54 source files to /tmp/build_b35db9c210bc86f2ba9870e2cd5d9474/target/classes
       [INFO] /tmp/build_b35db9c210bc86f2ba9870e2cd5d9474/src/main/java/tech/projectx/server/models/support/JacksonUtil.java: /tmp/build_b35db9c210bc86f2ba9870e2cd5d9474/src/main/java/tech/projectx/server/models/support/JacksonUtil.java uses unchecked or unsafe operations.
       [INFO] /tmp/build_b35db9c210bc86f2ba9870e2cd5d9474/src/main/java/tech/projectx/server/models/support/JacksonUtil.java: Recompile with -Xlint:unchecked for details.
       [INFO] 
       [INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ projectxserver ---
       [INFO] Using 'UTF-8' encoding to copy filtered resources.
       [INFO] Copying 1 resource
       [INFO] 
       [INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ projectxserver ---
       [INFO] Changes detected - recompiling the module!
       [INFO] Compiling 1 source file to /tmp/build_b35db9c210bc86f2ba9870e2cd5d9474/target/test-classes
       [INFO] 
       [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ projectxserver ---
       [INFO] Tests are skipped.
       [INFO] 
       [INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ projectxserver ---
       [INFO] Building jar: /tmp/build_b35db9c210bc86f2ba9870e2cd5d9474/target/projectxserver-1.0.0-SNAPSHOT.jar
       [INFO] 
       [INFO] --- spring-boot-maven-plugin:2.0.1.RELEASE:repackage (default) @ projectxserver ---
       [INFO] 
       [INFO] --- maven-dependency-plugin:3.0.2:copy (copy-new-relic-jar) @ projectxserver ---
       [INFO] Configured Artifact: com.newrelic.agent.java:newrelic-agent:?:jar
       [INFO] Copying newrelic-agent-4.0.0.jar to /tmp/build_b35db9c210bc86f2ba9870e2cd5d9474/target/newrelic-agent.jar
       [INFO] 
       [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ projectxserver ---
       [INFO] Installing /tmp/build_b35db9c210bc86f2ba9870e2cd5d9474/target/projectxserver-1.0.0-SNAPSHOT.jar to /app/tmp/cache/.m2/repository/tech/projectx/projectxserver/1.0.0-SNAPSHOT/projectxserver-1.0.0-SNAPSHOT.jar
       [INFO] Installing /tmp/build_b35db9c210bc86f2ba9870e2cd5d9474/pom.xml to /app/tmp/cache/.m2/repository/tech/projectx/projectxserver/1.0.0-SNAPSHOT/projectxserver-1.0.0-SNAPSHOT.pom
       [INFO] ------------------------------------------------------------------------
       [INFO] BUILD SUCCESS
       [INFO] ------------------------------------------------------------------------
       [INFO] Total time: 17.850 s
       [INFO] Finished at: 2018-05-08T19:10:25+00:00
       [INFO] Final Memory: 61M/410M
       [INFO] ------------------------------------------------------------------------
-----> Discovering process types
       Procfile declares types     -> (none)
       Default types for buildpack -> web
-----> Compressing...
       Done: 190.1M
-----> Launching...
       Released v46
       https://projectxserver-production.herokuapp.com/ deployed to Heroku

After re-deploying a few times, it started using the correct jar. Is Heroku picking up a random one?

Upvotes: 0

Views: 185

Answers (1)

codefinger
codefinger

Reputation: 10318

Heroku tries to automatically figure out the command to run your app when it detects that you are using Spring Boot. However, since the new-relic JAR is in your target/ directory, it thinks that it is your app.

You can fix this in two ways:

  1. Put the new-relic jar in a different directory (Heroku recommends target/dependency or similar).
  2. Create a Procfile and explicitly tell Heroku the command needed to run your app.

If you create a Procfile it will probably look like this:

web: java -Dserver.port=$PORT -javaagent:target/newrelic-agent.jar -jar target/projectxserver-1.0.0-SNAPSHOT.jar

Then run:

git add Procfile
git commit -m "Procfile"
git push heroku master

You can see the logic for the default command in the Java buildpack's bin/release script.

Upvotes: 1

Related Questions