如何在 heroku procfile 中设置 java 代理路径?

How to set java agent path in heroku procfile?

在我的 heroku procfile 中,我已经添加了 java 这样的代理路径

web: java -javaagent:newrelic/newrelic.jar

在应用程序根文件夹中,我创建了 newrelic 文件夹并将 newrelic-java-5.13.0.zip 文件解压缩到此文件夹中。

这是我的 Procfile:

但我收到以下错误:

app/web.1: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
 app/web.1: Picked up JAVA_TOOL_OPTIONS: -Xmx671m -XX:CICompilerCount=2 -Dfile.encoding=UTF-8 
 app/web.1: Jun 29, 2020 11:38:27 +0000 [4 1] com.newrelic INFO: New Relic Agent: Loading configuration file "/app/newrelic/./newrelic.yml"
 app/web.1: Jun 29, 2020 11:38:27 +0000 [4 1] com.newrelic INFO: Using default collector host: collector.newrelic.com
 app/web.1: Jun 29, 2020 11:38:28 +0000 [4 1] com.newrelic INFO: New Relic Agent v5.13.0 is initializing...
 app/web.1: Jun 29, 2020 11:38:30 +0000 [4 11] com.newrelic INFO: Instrumentation com.newrelic.instrumentation.jdbc-resultset is disabled. Skipping.
 app/web.1: Jun 29, 2020 11:38:35 +0000 [4 1] com.newrelic.agent.RPMServiceManagerImpl INFO: Configured to connect to New Relic at collector.newrelic.com:443
 app/web.1: Jun 29, 2020 11:38:36 +0000 [4 1] com.newrelic INFO: Setting audit_mode to false
 app/web.1: Jun 29, 2020 11:38:36 +0000 [4 1] com.newrelic INFO: Setting protocol to "https"
 app/web.1: Jun 29, 2020 11:38:36 +0000 [4 1] com.newrelic INFO: Agent class loader: com.newrelic.bootstrap.BootstrapAgent$JVMAgentClassLoader@25f38edc
 app/web.1: Jun 29, 2020 11:38:36 +0000 [4 1] com.newrelic INFO: Premain startup complete in 10,888ms
 app/web.1: Usage: java [-options] class [args...]
 app/web.1:            (to execute a class)
 app/web.1: where options include:
 app/web.1:     -d32      use a 32-bit data model if available
 app/web.1:     -d64      use a 64-bit data model if available
 app/web.1:     -server   to select the "server" VM
 app/web.1:                   because you are running on a server-class machine.
 app/web.1: 
 app/web.1: 
 app/web.1:     -cp <class search path of directories and zip/jar files>
 app/web.1:     -classpath <class search path of directories and zip/jar files>
 app/web.1:                   A : separated list of directories, JAR archives,
 app/web.1:                   and ZIP archives to search for class files.
 app/web.1:     -D<name>=<value>
 app/web.1:                   set a system property
 app/web.1:     -verbose:[class|gc|jni]
 app/web.1:                   enable verbose output
 app/web.1:     -version      print product version and exit
 app/web.1:     -version:<value>
 app/web.1: Jun 29, 2020 11:38:37 +0000 [4 6] com.newrelic.agent.core.CoreServiceImpl INFO: JVM is shutting down
 app/web.1: Jun 29, 2020 11:38:37 +0000 [4 6] com.newrelic.agent.core.CoreServiceImpl INFO: New Relic Agent has shutdown
 heroku/web.1: State changed from starting to crashed

注意:我的应用程序生成一个 war 文件,而不是 jar 文件。那么我需要将 jar 转换为 war 文件吗?

您只需要一个 web 流程类型,如下所示:

web: java -javaagent:newrelic/newrelic.jar $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war


或者,您可以将 -javaagent:newrelic/newrelic.jar 添加到您的 JAVA_OPTSheroku config:set JAVA_OPTS="-javaagent:newrelic/newrelic.jar" 并使用

web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war