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

时间:2018-05-08 19:09:29

标签: 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是随机挑选的吗?

1 个答案:

答案 0 :(得分:1)

当Heroku检测到您正在使用Spring Boot时,会尝试自动找出运行应用程序的命令。但是,由于新文件JAR位于您的target/目录中,因此它认为它是您的应用程序。

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

  1. 将新文物罐放在不同的目录中(Heroku推荐target/dependency或类似)。
  2. 创建Procfile并明确告诉Heroku运行应用程序所需的命令。
  3. 如果你创建一个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中看到默认命令的逻辑。