java - 为什么 Heroku 尝试运行 newrelic-agent.jar 而不是我的应用程序?

标签 java heroku newrelic

我的应用程序正在运行,它正在暂存中运行,但是在将该版本推送到生产环境后,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/ 目录中,因此它认为它是您的应用程序。

您可以通过两种方式解决此问题:

  1. 将 new-relic jar 放在不同的目录中(Heroku 建议 target/dependency 或类似目录)。
  2. 创建一个 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中查看默认命令的逻辑。 .

关于java - 为什么 Heroku 尝试运行 newrelic-agent.jar 而不是我的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50240749/

相关文章:

Heroku 控制台和新遗物(雪松堆栈)

performance - Newrelic intrumentation 减慢了 Grails 服务的初始化速度

java - Spring 交易未提交

java - java getBytes 与 getBytes(charset) 的奇怪行为

java - 为什么 Object.class 与 new Object().getClass() 不同?

java - HttpServletRequest 字段可能不是静态的、最终的或有 Jersey 2 的注释类型错误

ruby-on-rails - 将 RMagick 生成的文件从 Heroku 上传到 Amazon S3

javascript - Codecademy 练习 : portfolio

java - Heroku嵌入式Jetty端口绑定(bind)超时

azure - 根据构建配置禁用/启用 Azure 启动任务