为什么 Heroku 尝试 运行 newrelic-agent.jar 而不是我的应用程序?
Why is Heroku attempting to run newrelic-agent.jar instead of my app?
我的应用程序正在运行,它正在暂存中运行,但是在将该构建推送到生产环境之后,Heroku 运行正在执行此命令:
java -Dserver.port=12366 -javaagent:target/newrelic-agent.jar -jar target/newrelic-agent.jar
为什么 Heroku 试图 运行 newrelic-agent.jar
而不是我应用程序的 jar?
我的构建日志如下所示:
-----> 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
重新部署几次后,它开始使用正确的 jar。 Heroku 是随机选择一个吗?
当 Heroku 检测到您正在使用 Spring Boot.但是,由于 new-relic JAR 在您的 target/
目录中,它认为它是您的应用程序。
您可以通过两种方式解决此问题:
- 将 new-relic jar 放在不同的目录中(Heroku 推荐
target/dependency
或类似目录)。
- 创建一个
Procfile
并明确告诉 Heroku 运行 您的应用程序所需的命令。
如果你创建一个 Procfile
它可能看起来像这样:
web: java -Dserver.port=$PORT -javaagent:target/newrelic-agent.jar -jar target/projectxserver-1.0.0-SNAPSHOT.jar
然后运行:
git add Procfile
git commit -m "Procfile"
git push heroku master
您可以在 Java buildpack's bin/release script 中查看默认命令的逻辑。
我的应用程序正在运行,它正在暂存中运行,但是在将该构建推送到生产环境之后,Heroku 运行正在执行此命令:
java -Dserver.port=12366 -javaagent:target/newrelic-agent.jar -jar target/newrelic-agent.jar
为什么 Heroku 试图 运行 newrelic-agent.jar
而不是我应用程序的 jar?
我的构建日志如下所示:
-----> 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
重新部署几次后,它开始使用正确的 jar。 Heroku 是随机选择一个吗?
当 Heroku 检测到您正在使用 Spring Boot.但是,由于 new-relic JAR 在您的 target/
目录中,它认为它是您的应用程序。
您可以通过两种方式解决此问题:
- 将 new-relic jar 放在不同的目录中(Heroku 推荐
target/dependency
或类似目录)。 - 创建一个
Procfile
并明确告诉 Heroku 运行 您的应用程序所需的命令。
如果你创建一个 Procfile
它可能看起来像这样:
web: java -Dserver.port=$PORT -javaagent:target/newrelic-agent.jar -jar target/projectxserver-1.0.0-SNAPSHOT.jar
然后运行:
git add Procfile
git commit -m "Procfile"
git push heroku master
您可以在 Java buildpack's bin/release script 中查看默认命令的逻辑。