# Unable to configure Elastic APM with Java App

**URL:** <https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329>\
**Category:** APM\
**Tags:** java\
**Created:** [July 19, 2019, 7:03am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329 "2019-07-19T07:03:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [July 19, 2019, 7:03am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/1 "2019-07-19T07:03:35Z")

</div>

Hello team

I'm trying to integrate apm with java app.

**Kibana version** : 7.1.1

**Elasticsearch version** : 7.1.1

**APM Server version** : 7.2.0

**APM Agent language and version** : Java 1.7.0

Java App: [https://github.com/elastic/spring-petclinic](https://github.com/elastic/spring-petclinic)

Java app is up and running(on AWS EC-2):  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/6/76f5a9455b08f3ce637767254b726b967a71e693.png)

APM is running too  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/8/2842e1e9b81a0f338321ea671584edd9834b7672.png)

APM is configured in Java as a jar. you can see it here  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/f/ef8ad24b9de9e508c8aca7be04d4f3bf16876b33.png)

Now, How do I make sure the logs from java app are being sent to apm server and then to elasticsearch. I dont see any service related to java in kibana.

 ![image.png](https://us1.discourse-cdn.com/elastic/original/3X/3/c/3c8abd43e5e81ce8123ca68e825eee744d97db90.png)

I tried this option in cmd to configure java app with apm:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/c/2c456d1ce595c51c11aed5744d00c51f5bd84e79.png)

Is there anything that I need to do while running java app.

Please suggest

Thanks for your time as always 🙂

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [July 19, 2019, 7:50am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/2 "2019-07-19T07:50:13Z")

</div>

> [@rahulnama](#):
>
> APM is configured in Java as a jar. you can see it here

You only need to do this if you actually want to enhance the traces via the [public API](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html). I suggest to remove that until you need it. You are also using a very old version of the API.

> [@rahulnama](#):
>
> I tried this option in cmd to configure java app with apm:

You are using the wrong jar to runtime attach to your application. See the [installation instructions](https://www.elastic.co/guide/en/apm/agent/java/current/setup-attach-cli.html) where to download the correct jar for remote attachment.

---

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [July 19, 2019, 11:08am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/3 "2019-07-19T11:08:13Z")

</div>

Thank you @felixbarny

Running with command. Stuck here, can you please suggest, I tried changing jdk path in env variables but couldnt work.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/a/2aaa123e6e19866e0b74b5eb367a36e0aa1ceaea.png)

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [July 19, 2019, 11:19am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/4 "2019-07-19T11:19:23Z")

</div>

can you send all Path variable value?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [July 19, 2019, 11:34am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/5 "2019-07-19T11:34:07Z")

</div>

As the exception message suggests, you are probably trying to attach with a JRE but attaching requires a JDK. Could you send me the output of `java -version`?

---

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [July 19, 2019, 12:34pm UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/6 "2019-07-19T12:34:04Z")

</div>

Here it is

![image](https://us1.discourse-cdn.com/elastic/original/3X/a/b/abe91a52407ea51478ce4ab9cfe72d0d3bc61ab2.png)

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [July 21, 2019, 5:22am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/7 "2019-07-21T05:22:15Z")

</div>

Please try to verify that the java command you are using is coming from a JDK bin and `jre/bin`.  
Regardless, any reason why you can't install the agent through [the `-javaagent` configuration](https://www.elastic.co/guide/en/apm/agent/java/current/setup-javaagent.html)?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 21, 2019, 6:36am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/8 "2019-07-21T06:36:44Z")

</div>

First can you echo your JAVA\_HOME it is still unclear if you are using a JRE or JDK

`echo $JAVA_HOME`

Also your your startup command should look something like the following, substitute the URL of your APM Server. You do not need the APM as part of the dependency for the application to use the automatic instrumentation.

```
java -javaagent:./elastic-apm-agent-1.7.0.jar \
-Delastic.apm.server_urls="http://localhost:8200" \
-Delastic.apm.service_name="spring-petclinic-monolith" \
-Delastic.apm.application_packages="org.springframework.samples" \
-Delastic.apm.trace_methods="org.springframework.samples.petclinic.*" \
-jar target/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar

```

A complete quick sample on how to run Petclinic with APM can be found here. You can ignore the docker stuff but it shows you how to build and run Petclinic and get APM data. This is a fork that I put a performance bug in that you can find with APM

> <https://gist.github.com/bvader/cc9fea7e6f8f709dfa2ad14776eed7fe>

---

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [July 23, 2019, 10:19am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/9 "2019-07-23T10:19:38Z")

</div>

Hey @stephenb

I've followed the same procedure and able to configure for the java app. It's working well

And, the spring pet-clinic app you have mentioned is monolith. I've also configured it for micro-services based pet-clinic app([https://github.com/elastic/spring-petclinic](https://github.com/elastic/spring-petclinic)).  
Configured it for java, python. trying to set up front end. Not much aware of how to start the front-end app. I'm exploring, please let me know if you are aware of it.

Also, I've one question related to java apm.

I also wanted to monitor jvm and threads. Is there any way using APM ? or do i need to use beats for that ?

Thanks for your time

Best  
Rahul

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [July 23, 2019, 11:54am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/10 "2019-07-23T11:54:33Z")

</div>

@rahulnama the Java agent is [sending JVM metrics](https://www.elastic.co/guide/en/apm/agent/java/current/metrics.html) that are stored in dedicated APM indices.  
Since Kibana version 7.2, the APM UI also shows JVM memory and thread count on the Metrics tab.  
There is a work going on to expand that to show more JVM metrics (like GC), better filtering options and more in upcoming releases.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 23, 2019, 1:51pm UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/11 "2019-07-23T13:51:30Z")

</div>

If you want a little better instructions on the real user monitoring RUM check out this [blog](https://www.elastic.co/blog/performing-real-user-monitoring-rum-with-elastic-apm)

---

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [July 23, 2019, 2:10pm UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/12 "2019-07-23T14:10:03Z")

</div>

Well, that’s great stuff. It used to be very difficult with beats configuring jolokia jmx and all. Awesome feature this is. I will try it out soon

Thanks for the great news 🙂

---

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [July 23, 2019, 2:10pm UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/13 "2019-07-23T14:10:25Z")

</div>

Thanks. That helps

---

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [July 26, 2019, 8:49am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/14 "2019-07-26T08:49:54Z")

</div>

hey @stephenb

Stuck with a typical requirement.

All my java apps are running in production(assume on ec2 instances). Now I've to integrate them with APM without re-deploying/re-starting the java app. how to achieve this. We are using ansible for remote installation of apm on different machines.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [July 26, 2019, 10:42am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/15 "2019-07-26T10:42:28Z")

</div>

The attacher allows to instrument running applications without a restart: [https://www.elastic.co/guide/en/apm/agent/java/current/setup-attach-cli.html](https://www.elastic.co/guide/en/apm/agent/java/current/setup-attach-cli.html)

---

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [July 28, 2019, 2:52pm UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/16 "2019-07-28T14:52:54Z")

</div>

Thank you @felixbarny  
will look into it.

---

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [July 29, 2019, 8:41am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/17 "2019-07-29T08:41:48Z")

</div>

Hello @stephenb

Running the spring pet-clinic app: Integrated with apm and working fine.

But, Once I click on Error Page, In kibana I see the number of occurrences very high(Though I actually hit the error page only once)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/9/39673c890e5be4437ce8b66d0e312c0cdc78f54b.png)

If you see in the image it's displaying number of occurences as 214 and 56 in last 5 mins. However, I've clicked the error page only 6-7 times. not sure why is it showing such a high count ?  
Any suggestions ?

---

<div class="post-metadata">

**Author:** ![rahulnama](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rahulnama](https://discuss.elastic.co/u/rahulnama)\
**Post date:** [August 14, 2019, 10:57am UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/18 "2019-08-14T10:57:14Z")

</div>

Hello @stephenb

Running petclinic app. need your help.  
I want to use mysql (instead of hsqldb)which is installed on AWS ec2. In that case I can also track the mysql metrics and query logs using packetbeat and filebeat.

Could you explain me how to configure mysql for spring-petclinic?

I've changed the details of mysql in appliation.properties file.  
And also I've changed database=mysql(hsqldb). Also tried running scripts manually.

but when I build and run I see lot of errors. could you let me know what else is needed to run app with mysql running on localhost.

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [August 14, 2019, 6:36pm UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/19 "2019-08-14T18:36:00Z")

</div>

Hi @rahulnama

That is really `petclinic` related not elastic stack related there is a whole community and lots of help around petclinic perhaps you can share your error messages and get some help there... of course include your error messages because without them no one will be able to really help

Here are a couple places to look...

> **[spring-projects/spring-petclinic](https://github.com/spring-projects/spring-petclinic)**
>
> A sample Spring-based application. Contribute to spring-projects/spring-petclinic development by creating an account on GitHub.

[https://projects.spring.io/spring-petclinic/](https://projects.spring.io/spring-petclinic/)

[https://spring-petclinic.github.io/](https://spring-petclinic.github.io/)

[https://spring-petclinic.github.io/docs/forks.html](https://spring-petclinic.github.io/docs/forks.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 4, 2019, 2:36pm UTC](https://discuss.elastic.co/t/unable-to-configure-elastic-apm-with-java-app/191329/20 "2019-09-04T14:36:01Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
