# Error while adding Java APM agent as dependency

**URL:** <https://discuss.elastic.co/t/error-while-adding-java-apm-agent-as-dependency/192602>\
**Category:** APM\
**Tags:** java\
**Created:** [July 29, 2019, 5:27am UTC](https://discuss.elastic.co/t/error-while-adding-java-apm-agent-as-dependency/192602 "2019-07-29T05:27:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pksinghal](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@pksinghal](https://discuss.elastic.co/u/pksinghal)\
**Post date:** [July 29, 2019, 5:27am UTC](https://discuss.elastic.co/t/error-while-adding-java-apm-agent-as-dependency/192602/1 "2019-07-29T05:27:19Z")

</div>

I want to do distributed tracking using Java APM.  
Initially, we use Java agent as manual setup with -javaagent flag and we get tracing data using this. Then we deploy this on our test server and its working fine.  
Now, to take this on production server, i try to add Java APM as dependency but its throwing error as follows:

[INFO] --- spring-boot-maven-plugin:2.1.6.RELEASE:run (default-cli) @ demo ---  
[INFO] Attaching agents:   
2019-07-29 10:41:47.841 [Attach Listener] INFO co.elastic.apm.agent.configuration.StartupInfo - Starting Elastic APM 1.7.0 as first on Java 1.8.0\_212 (Oracle Corporation) Linux 4.18.0-25-generic  
2019-07-29 10:41:47.841 [Attach Listener] WARN co.elastic.apm.agent.configuration.StartupInfo - To enable all features and to increase startup times, please configure application\_packages  
2019-07-29 10:41:47.925 [apm-server-healthcheck] INFO co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server is available: { "build\_date": "2019-06-20T14:39:23Z", "build\_sha": "9a099b63c53eac8c55707df96193143ec66337e9", "version": "7.2.0"}  
Exception in thread "restartedMain" 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 org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)  
Caused by: java.lang.IllegalStateException: Error during attachment using: co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@867f9f9  
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:427)  
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:298)  
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:273)  
at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:84)  
at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:55)  
at com.example.demo.DemoApplication.main(DemoApplication.java:11)  
... 5 more  
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:99)  
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:422)  
... 10 more  
Caused by: java.lang.UnsatisfiedLinkError: Native Library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/libattach.so already loaded in another classloader  
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1907)  
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845)  
at java.lang.Runtime.loadLibrary0(Runtime.java:870)  
at java.lang.System.loadLibrary(System.java:1122)  
at sun.tools.attach.LinuxVirtualMachine.(LinuxVirtualMachine.java:342)  
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)  
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)  
... 16 more

We are using Java APM version :1.7.0  
Code in pom.xml:  
  
co.elastic.apm  
apm-agent-attach  
1.7.0

---

<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:** [August 2, 2019, 9:28am UTC](https://discuss.elastic.co/t/error-while-adding-java-apm-agent-as-dependency/192602/2 "2019-08-02T09:28:05Z")

</div>

Sorry for not responding here - this was an oversight. Generally it's better to not re-create the issue ([Not able to add JAVA APM agent as dependency in spring boot project](https://discuss.elastic.co/t/not-able-to-add-java-apm-agent-as-dependency-in-spring-boot-project/193224)) but to ping on the same thread.

---

<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:** [August 23, 2019, 5:28am UTC](https://discuss.elastic.co/t/error-while-adding-java-apm-agent-as-dependency/192602/3 "2019-08-23T05:28:11Z")

</div>

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