# Java APM attached agent not launching

**URL:** <https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657>\
**Category:** APM\
**Tags:** java\
**Created:** [October 1, 2020, 11:21am UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657 "2020-10-01T11:21:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Angel\_Morena\_Si](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jose_angel_morena_si/32/76522_2.png) [@Jose\_Angel\_Morena\_Si](https://discuss.elastic.co/u/Jose_Angel_Morena_Si)\
**Post date:** [October 1, 2020, 11:21am UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/1 "2020-10-01T11:21:26Z")

</div>

Hello there,

I am trying to use the Automatic setup with `apm-agent-attach-standalone.jar`. I am running the agent with Oracle Java 8, and the java application I want to monitor is running with Java 7.

**Kibana version** : 7.9.0

**Elasticsearch version** : 7.9.2

**APM Server version** : 7.9.2

**APM Agent language and version** : Java Oracle 8, 1.18.0

**Browser version** : Google Chrome 80.0.3987.149

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**: The agent was installed from the link: [https://search.maven.org/remotecontent?filepath=co/elastic/apm/apm-agent-attach/1.18.0/apm-agent-attach-1.18.0-standalone.jar](https://search.maven.org/remotecontent?filepath=co/elastic/apm/apm-agent-attach/1.18.0/apm-agent-attach-1.18.0-standalone.jar)

**Fresh install or upgraded from other version?** Fresh install

**Is there anything special in your setup?** The communication between the agent and the APM server is plain within an internal network. The problem is the agent won't attach to the Java VM, so it has nothing to do with a communication issue with APM server.

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

```auto
[root@company jboss-as-7.1.1]# java -jar apm-agent-attach-1.18.0-standalone.jar --pid 27769 --config service_name=comerzzia-pre server_urls=http://192.168.250.114:8200
2020-10-01 13:16:17.631 INFO Attaching the Elastic APM agent to 27769
Exception in thread "main" java.lang.IllegalStateException: Error during attachment using: co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@3f8f9dd6
        at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:613)
        at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:273)
        at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:159)
        at co.elastic.apm.attach.RemoteAttacher.main(RemoteAttacher.java:88)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at co.elastic.apm.attach.bytebuddy.agent.Attacher.install(Attacher.java:106)
        at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:608)
        ... 3 more
Caused by: java.lang.IllegalStateException: Target VM did not respond: 27769
        at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot$Connection$Factory$ForSocketFile.connect(VirtualMachine.java:541)
        at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot.attach(VirtualMachine.java:256)
        at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot.attach(VirtualMachine.java:243)
        ... 9 more

```

Apparently, no matter the java version I use when launching the agent (Java 7 or Java 8), it won't attach to the JVM of the Java 7 process.  
The command I use to launch the agent is the following:  
`java -jar $(pwd)/apm-agent-attach-1.18.0-standalone.jar --pid $(ps -C java -f | grep -i standalone | awk '{print $2}') --config service_name=comerzzia-pre server_urls=http://192.168.250.114 :8200 applicaion_packages=bin.comerzzia,org.apache.jsp.backoffice,org.jboss.byteman log_file=/apps/bin/comerzzia/jboss-as-7.1.1/standalone/log/apm.log log_level=DEBUG`

Is there any additional step I am missing? Any help provided is welcome!

Thanks in advance!

---

<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:** [October 1, 2020, 11:41am UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/2 "2020-10-01T11:41:18Z")

</div>

Hi and welcome to our forum!

Try running the standalone jar with the same Java you use to run the application

---

<div class="post-metadata">

**Author:** ![Jose\_Angel\_Morena\_Si](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jose_angel_morena_si/32/76522_2.png) [@Jose\_Angel\_Morena\_Si](https://discuss.elastic.co/u/Jose_Angel_Morena_Si)\
**Post date:** [October 1, 2020, 11:55am UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/3 "2020-10-01T11:55:25Z")

</div>

Hello Eyal, thanks for your quick response!

Apparenty, the error is still the same.

```auto
[root@company jboss-as-7.1.1]# ps -C java -o pid,cmd
  PID CMD
27769 /apps/bin/comerzzia/jdk1.7.0_80/bin/java -D[Standalone] -server -XX:+UseCompressedOops -XX:+TieredCompilation -Duser.timezone=Europe/Madrid -Xms8192m -Xmx8192m -XX:MaxPermSize=2048m -
[root@company jboss-as-7.1.1]# /apps/bin/comerzzia/jdk1.7.0_80/bin/java -jar apm-agent-attach-1.18.0-standalone.jar --pid 27769 --config service_name=comerzzia-pre server_urls=http://192.168.250.114:8200
2020-10-01 13:54:19.797 INFO Attaching the Elastic APM agent to 27769
Exception in thread "main" java.lang.IllegalStateException: Error during attachment using: co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@3d6998b9
        at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:613)
        at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:273)
        at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:159)
        at co.elastic.apm.attach.RemoteAttacher.main(RemoteAttacher.java:88)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at co.elastic.apm.attach.bytebuddy.agent.Attacher.install(Attacher.java:106)
        at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:608)
        ... 3 more
Caused by: java.lang.IllegalStateException: Target VM did not respond: 27769
        at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot$Connection$Factory$ForSocketFile.connect(VirtualMachine.java:541)
        at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot.attach(VirtualMachine.java:256)
        at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot.attach(VirtualMachine.java:243)
        ... 9 more
[root@company jboss-as-7.1.1]# 

```

---

<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:** [October 1, 2020, 1:29pm UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/4 "2020-10-01T13:29:30Z")

</div>

Just saw your command line - seems like you trying to connect to the JVM running the standalone jar...

The process you provide for `--pid` should be that of the JVM you want to attach to.

Also, you should use the same user to run the standalone jar as the user running the target JVM.

I hope this helps

---

<div class="post-metadata">

**Author:** ![Jose\_Angel\_Morena\_Si](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jose_angel_morena_si/32/76522_2.png) [@Jose\_Angel\_Morena\_Si](https://discuss.elastic.co/u/Jose_Angel_Morena_Si)\
**Post date:** [October 1, 2020, 2:19pm UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/5 "2020-10-01T14:19:14Z")

</div>

Hello Eyal,

I updated my startup script for the agent so it is runned by jboss user. Btw, jboss is the user that runs the java 7 process I want to monitor. I am still using java 8 to monitor my java 7 server.

The script looks like this:

```auto
#!/usr/bin/bash
sudo -E -u jboss java -jar $(pwd)/apm-agent-attach-1.18.0-standalone.jar --pid $(ps -C java -f | grep -i standalone | awk '{print $2}') --config service_name=comerzzia-pre server_urls=http
://192.168.250.114:8200 applicaion_packages=bin.comerzzia,org.apache.jsp.backoffice,org.jboss.byteman log_file=/apps/bin/comerzzia/jboss-as-7.1.1/standalone/log/apm.log log_level=DEBUG

```

At this very moment, the aforementioned error of the agent not being able to bind itself with the JVM process has dissappeared. The logs look like the following:

```auto
[root@company jboss-as-7.1.1]# ./launch_apm_java_agent.sh 
2020-10-01 16:16:34.367 INFO Attaching the Elastic APM agent to 27769
2020-10-01 16:16:34.635 INFO Done
[root@company jboss-as-7.1.1]# 

```

Is this behaviour normal? Should not the agent be in background monitoring continuously? Besides, I cannot see any log in the path `/apps/bin/comerzzia/jboss-as-7.1.1/standalone/log/apm.log`

Thanks for your help and support Eyal,

---

<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:** [October 1, 2020, 2:31pm UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/6 "2020-10-01T14:31:09Z")

</div>

Ahh, you `grep` for the JBoss `standalone`...

You would need a `--config` (or `-C`) before each config option. After you fix that, you should be good to go. Good luck!

---

<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:** [October 1, 2020, 2:39pm UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/7 "2020-10-01T14:39:26Z")

</div>

BTW, since you already attached the agent before, you may need to restart your JBoss this time. There is no `detach` option. The behaviour you see is normal - the agent is attached and the attaching process terminates. The continuous mode is for cases where you want any new JVM starting up on the host to be attached soon after it starts. When you want to attach to a single process which you know is already running, what you did is the way to go.

---

<div class="post-metadata">

**Author:** ![Jose\_Angel\_Morena\_Si](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jose_angel_morena_si/32/76522_2.png) [@Jose\_Angel\_Morena\_Si](https://discuss.elastic.co/u/Jose_Angel_Morena_Si)\
**Post date:** [October 1, 2020, 2:47pm UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/8 "2020-10-01T14:47:48Z")

</div>

Hello, I added the `--config` flag after each of the options.

I assume that the behaviour is normal and it is working as expected.

Summarizing, the idea is that the java process finishes because its main thread only handles the attachment JVM process. Taking this information into account, if I ever want to finish the agent the only thing I have to do is reboot my Java JBOSS applicattion. Am I right? Is there anything I misunderstood?

Thanks for all your help!

Best,

---

<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:** [October 4, 2020, 12:04pm UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/9 "2020-10-04T12:04:01Z")

</div>

> [@Jose\_Angel\_Morena\_Si](#):
>
> Summarizing, the idea is that the java process finishes because its main thread only handles the attachment JVM process.

That is correct, as long as you don't use it in the continuous mode.

> [@Jose\_Angel\_Morena\_Si](#):
>
> if I ever want to finish the agent the only thing I have to do is reboot my Java JBOSS applicattion. Am I right? Is there anything I misunderstood?

Well, I said there is no complete `detach`, meaning no way to completely unload agent code from the JVM. However, the is certainly a way to disable the agent in runtime through the [`recording`](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-recording) config. Furthermore, you can reverse agent bytecode instrumentation in runtime through the [`instrument`](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-instrument) config.  
These config options are [dynamic](https://www.elastic.co/guide/en/apm/agent/java/current/configuration.html#configuration-dynamic), check out how such options can be utilized.

Good luck!

---

<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:** [October 25, 2020, 8:04am UTC](https://discuss.elastic.co/t/java-apm-attached-agent-not-launching/250657/10 "2020-10-25T08:04:18Z")

</div>

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