# Unable to export CLASSPATH for localhost on Ansible on Linux Redhat

**URL:** <https://forum.ansible.com/t/unable-to-export-classpath-for-localhost-on-ansible-on-linux-redhat/35495>\
**Category:** Ansible Project\
**Created:** [July 13, 2021, 8:04am UTC](https://forum.ansible.com/t/unable-to-export-classpath-for-localhost-on-ansible-on-linux-redhat/35495 "2021-07-13T08:04:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Easy\_King](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@Easy\_King](https://forum.ansible.com/u/Easy_King)\
**Post date:** [July 13, 2021, 8:04am UTC](https://forum.ansible.com/t/unable-to-export-classpath-for-localhost-on-ansible-on-linux-redhat/35495/1 "2021-07-13T08:04:09Z")

</div>

I get the below error while executing the shell command on ansible localhost

$ java utils.dbping ORACLE\_THIN :: Error: Could not find or load main class utils.dbping

Inorder, to resolve this error i set the classpath like below:

export CLASSPATH=/web/playbooks/automation/libraries/com.bea.core.datasource6.jar

With this the java utils.dbping command works fine.

I try the same command in ansible on localhost as below:

47 - name: Check DB connection with DBPING48 shell: “java utils.dbping ORACLE\_THIN ::”  
49 environment:  
50 CLASSPATH: “/web/playbooks/automation/libraries/com.bea.core.datasource6.jar”  
51 PATH: “/web/jdk1.8.0\_291/bin”  
52 delegate\_to: localhost

But I get the below error indicating that the CLASSPATH was not set correctly.

02:57:43 failed: [remotehost7 → localhost] =\> {“changed”: true, “cmd”: “java utils.dbping”, “delta”: “0:00:00.078752”, “end”: “2021-07-12 17:27:43.616820”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2021-07-12 17:27:43.538068”, “stderr”: “java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver\n\tat java.net.URLClassLoader.findClass(URLClassLoader.java:382)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:418)\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:351)\n\tat java.lang.Class.forName0(Native Method)\n\tat java.lang.Class.forName(Class.java:264)\n\tat utils.dbping.main(dbping.java:282)”, “stderr\_lines”: [“java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver”, “\tat java.net.URLClassLoader.findClass(URLClassLoader.java:382)”, “\tat java.lang.ClassLoader.loadClass(ClassLoader.java:418)”, “\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)”, “\tat java.lang.ClassLoader.loadClass(ClassLoader.java:351)”, “\tat java.lang.Class.forName0(Native Method)”, “\tat java.lang.Class.forName(Class.java:264)”, “\tat utils.dbping.main(dbping.java:282)”], “stdout”: “\nError encountered:”, “stdout\_lines”: [“”, “Error encountered:”]}

I even tried CLASSPATH: “/web/playbooks/automation/libraries/com.bea.core.datasource6.jar:.:” but that too did not help.

I also tried java -cp option but still no luck.

I prefer to mention the CLASSPATH in ansible rather than in shell prompt along with ansible command.

Can you please suggest?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 13, 2021, 9:37am UTC](https://forum.ansible.com/t/unable-to-export-classpath-for-localhost-on-ansible-on-linux-redhat/35495/2 "2021-07-13T09:37:29Z")

</div>

You only provided the path to reach utils.dbping.  
But your error now says:

java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver

This is a different class missing.  
Basically you need to provide ALL required paths in CLASSPATH.

---

<div class="post-metadata">

**Author:** ![Easy\_King](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@Easy\_King](https://forum.ansible.com/u/Easy_King)\
**Post date:** [July 13, 2021, 4:24pm UTC](https://forum.ansible.com/t/unable-to-export-classpath-for-localhost-on-ansible-on-linux-redhat/35495/3 "2021-07-13T16:24:34Z")

</div>

Dick Hi,

Your suggestion helped!!

Thank you.
