このドキュメントでは、Maven を使用して Java エージェントをインストールする方法を説明します。Java エージェントを手動でインストールする方法については、 Java エージェントのインストール および Java エージェントの構成を参照してください。コンフィグファイル.
Mavenによるエージェントパッケージのインストール
以下のいずれかの方法で、New Relic Java エージェントをインストールします。
ここでは、New Relic Java エージェントコンポーネントがすべて含まれている
newrelic-java.zip
ファイルをダウンロードして解凍するように Maven を設定する方法を説明します。newrelic.yml
(エージェント設定ファイル)newrelic.jar
(Java agent jar)newrelic-api.jar
(Java agent API jar)READMEをご覧ください
そのためには
pom.xml
newrelic-java.zip
をダウンロードするように設定します。例えば、以下のようになります。<dependency> <groupId>com.newrelic.agent.java</groupId> <artifactId>newrelic-java</artifactId> <version>JAVA_AGENT_VERSION</version> <scope>provided</scope> <type>zip</type> </dependency>
JAVA_AGENT_VERSION を 最新の Java エージェントバージョン に置き換えてください。
newrelic-java.zip
を、maven-dependency-plugin
をpom.xml
で設定して解凍します。たとえば、以下のようになります。<!-- Unzip New Relic Java agent into target/ --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>3.1.1</version><executions><execution><id>unpack-newrelic</id><phase>package</phase><goals><goal>unpack-dependencies</goal></goals><configuration><includeGroupIds>com.newrelic.agent.java</includeGroupIds><includeArtifactIds>newrelic-java</includeArtifactIds><!-- you can optionally exclude files --><!-- <excludes>**/newrelic.yml</excludes> --><overWriteReleases>false</overWriteReleases><overWriteSnapshots>false</overWriteSnapshots><overWriteIfNewer>true</overWriteIfNewer><outputDirectory>${project.build.directory}</outputDirectory></configuration></execution></executions></plugin>これにより、すべてのファイルが、
newrelic/
project.build.directory
内に新たに作成されたファイルに解凍されます。以下は、
pom.xml
をダウンロードして抽出する例です。newrelic-java.zip
.<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.example.application</groupId><artifactId>my-example-app</artifactId><packaging>war</packaging><version>1.0</version><name>My Example Application</name><url>http://example.com</url><dependencies><dependency><groupId>com.newrelic.agent.java</groupId><artifactId>newrelic-java</artifactId><version>JAVA_AGENT_VERSION</version><scope>provided</scope><type>zip</type></dependency></dependencies><!-- boilerplate code so Maven can generate a .war archive without requiring a web.xml file --><build><finalName>my-example-app</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.2.2</version><configuration><failOnMissingWebXml>false</failOnMissingWebXml></configuration></plugin><!-- Unzip New Relic Java agent into project.build.directory --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>3.1.1</version><executions><execution><id>unpack-newrelic</id><phase>package</phase><goals><goal>unpack-dependencies</goal></goals><configuration><includeGroupIds>com.newrelic.agent.java</includeGroupIds><includeArtifactIds>newrelic-java</includeArtifactIds><overWriteReleases>false</overWriteReleases><overWriteSnapshots>false</overWriteSnapshots><overWriteIfNewer>true</overWriteIfNewer><outputDirectory>${project.build.directory}</outputDirectory></configuration></execution></executions></plugin></plugins></build></project>
このセクションでは、Javaエージェントの個々のコンポーネントをダウンロードするためにMavenを設定する方法を説明します。具体的には、
newrelic.jar
とnewrelic-api.jar
です。pom.xml
newrelic.jar
ornewrelic-api.jar
のいずれかをダウンロードするように設定します。以下は、newrelic.jar
をダウンロードする例です。<dependency> <groupId>com.newrelic.agent.java</groupId> <artifactId>newrelic-agent</artifactId> <version>JAVA_AGENT_VERSION</version> <scope>provided</scope> </dependency>
以下はダウンロードの例です。
newrelic-api.jar
:<dependency> <groupId>com.newrelic.agent.java</groupId> <artifactId>newrelic-api</artifactId> <version>JAVA_AGENT_VERSION</version> <scope>compile</scope> </dependency>
JAVA_AGENT_VERSION を 最新の Java エージェントバージョン に置き換えてください。
New Relic アカウント作成時に受け取った
newrelic.yml
ファイルを探すか、使用しているエージェントの バージョン のものをダウンロードします。ここでは、個々のコンポーネント(JavaエージェントとAPIジャー)を操作するための例として、
pom.xml
を紹介します。<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.example.application</groupId><artifactId>my-example-app</artifactId><packaging>war</packaging><version>1.0</version><name>My Example Application</name><url>http://example.com</url><dependencies><!-- The newrelic.jar dependency. --><dependency><groupId>com.newrelic.agent.java</groupId><artifactId>newrelic-agent</artifactId><version>3.47.1</version><scope>provided</scope></dependency><!-- The newrelic-api.jar dependency. --><dependency><groupId>com.newrelic.agent.java</groupId><artifactId>newrelic-api</artifactId><version>3.47.1</version><scope>compile</scope></dependency></project>
newrelic.yml
をnewrelic.jar
と同じフォルダーに置く。JVM arg-Dnewrelic.config.file
で特に指定しない限り、このようにする。newrelic.yml
ファイル (または JVM system properties) に、license_key
とapp_name
を設定します。-javaagent:/path/to/newrelic.jar
をアプリケーションサーバが動作しているJVMに渡します。オプション: New Relic Java agent API を使用する場合は、アプリケーションクラスパスに API jar を追加して、コンパイル時に利用できるようにします。
アプリのトラフィックを生成し、 APM Summary page にデータが表示されるまで数分待ちます。何も表示されない場合は、 トラブルシューティングの手順に従ってください 。