# Adding java agent on Tomcat 8

**URL:** <https://discuss.elastic.co/t/adding-java-agent-on-tomcat-8/243067>\
**Category:** APM\
**Tags:** java\
**Created:** [July 29, 2020, 1:59pm UTC](https://discuss.elastic.co/t/adding-java-agent-on-tomcat-8/243067 "2020-07-29T13:59:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danny\_Larsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danny_larsen/32/72800_2.png) [@Danny\_Larsen](https://discuss.elastic.co/u/Danny_Larsen)\
**Post date:** [July 29, 2020, 1:59pm UTC](https://discuss.elastic.co/t/adding-java-agent-on-tomcat-8/243067/1 "2020-07-29T13:59:25Z")

</div>

I am having trouble adding the Java agent to Tomcat 8 running in docker. This is the exception I get:

```
Error opening zip file or JAR manifest missing : /usr/local/tomcat/apm/elastic-apm-agent-1.16.0.jar
Error occurred during initialization of VM
agent library failed to init: instrument

```

I have checked that the jar file is there and have read permissions.  
It is the same error I get if I remove the file, so clearly the file is not visible by Tomcat.

This is my setenv.sh file:  
`export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/usr/local/tomcat/apm/elastic-apm-agent-1.16.0.jar"`

This is from my Dockerfile:

```auto
ADD ./lib/elastic-apm-agent-1.16.0.jar /usr/local/tomcat/apm/elastic-apm-agent-1.16.0.jar
ADD ./lib/setenv.sh /usr/local/tomcat/bin/setenv.sh
RUN chmod +x /usr/local/tomcat/bin/setenv.sh

```

It is running tomcat:8.5 (Have tried multiple images)

I am really stuck, so any help would be great.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [August 19, 2020, 7:57am UTC](https://discuss.elastic.co/t/adding-java-agent-on-tomcat-8/243067/2 "2020-08-19T07:57:24Z")

</div>

Hi @Danny_Larsen,

This error message usually indicates that the agent jar file is not readable by the JVM process.

Could you add the following lines to your `setenv.sh` file and send us the output ?

```auto
echo $USER # prints user name running tomcat
ls -ahl /usr/local/tomcat/apm/elastic-apm-agent-1.16.0.jar # check file permissions
sha1sum /usr/local/tomcat/apm/elastic-apm-agent-1.16.0.jar # check file integrity

```

---

<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 9, 2020, 3:57am UTC](https://discuss.elastic.co/t/adding-java-agent-on-tomcat-8/243067/3 "2020-09-09T03:57:27Z")

</div>

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