JAVA_HOME error after install of jasper_erpnext_report

Continuing the discussion from Jasper Report: KeyError: 'JAVA_HOME':

after the installation of jasper_erpnext_report i can`t acces the ERPNext Desk of my fresh installation anymore.

Before the install-app i had to export the variable JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 which worked pretty good for the installation itself.

But after login i see get to see the following error, so it seems that there still is a problem in frappe finding the JAVA_HOME directory?

What can i do to trace down the problem?

Traceback (innermost last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 25, in render
    data = render_page_by_language(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 91, in render_page_by_language
    return render_page(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 113, in render_page
    return build(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 122, in build
    return build_method(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 138, in build_page
    context = get_context(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 31, in get_context
    context = build_context(context)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 79, in build_context
    ret = module.get_context(context)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/templates/pages/", line 21, in get_context
    boot = frappe.sessions.get()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 105, in get
    bootinfo = get_bootinfo()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 65, in get_bootinfo
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 771, in get_attr
    return getattr(get_module(modulename), methodname)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 590, in get_module
    return importlib.import_module(modulename)
  File "/usr/lib/python2.7/importlib/", line 37, in import_module
  File "/home/frappe/frappe-bench/apps/jasper_erpnext_report/jasper_erpnext_report/core/", line 13, in <module>
    import JasperRoot as Jr
  File "/home/frappe/frappe-bench/apps/jasper_erpnext_report/jasper_erpnext_report/core/", line 11, in <module>
    import JasperServer as Js, JasperLocal as Jl, JasperBase as Jb
  File "/home/frappe/frappe-bench/apps/jasper_erpnext_report/jasper_erpnext_report/core/", line 15, in <module>
    from jasper_erpnext_report.jasper_reports.FrappeDataSource import _JasperCustomDataSource
  File "/home/frappe/frappe-bench/apps/jasper_erpnext_report/jasper_erpnext_report/jasper_reports/", line 4, in <module>
    from jnius import PythonJavaClass, java_method
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jnius/", line 13, in <module>
    from .reflect import *
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jnius/", line 14, in <module>
    class Class(with_metaclass(MetaJavaClass, JavaClass)):
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/", line 808, in __new__
    return meta(name, bases, d)
  File "jnius/jnius_export_class.pxi", line 43, in jnius.MetaJavaClass.__new__ (jnius/jnius.c:17159)
  File "jnius/jnius_export_class.pxi", line 65, in jnius.MetaJavaClass.resolve_class (jnius/jnius.c:17555)
  File "jnius/jnius_env.pxi", line 11, in jnius.get_jnienv (jnius/jnius.c:3320)
  File "jnius/jnius_jvm_dlopen.pxi", line 89, in jnius.get_platform_jnienv (jnius/jnius.c:3248)
  File "jnius/jnius_jvm_dlopen.pxi", line 48, in jnius.create_jnienv (jnius/jnius.c:2647)
  File "/home/frappe/frappe-bench/env/lib/python2.7/", line 23, in __getitem__
    raise KeyError(key)
 KeyError: 'JAVA_HOME'

It seems JAVA_HOME environment variable was not properly set after JDK package installation. (If you are sure, JDK is installed as it is one of the main pre-requisite to make jasper_erpnext_report module work)

You can setup JAVA_HOME all users, I would recommend placing the following line in /etc/profile

export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
source /etc/profile

This will update dynamically and works well with the alternatives system.
Note: The update will only take place in a new login shell, so Logout and Log Back to Shell to make this new environment variable work.

And then try to run plugin setup steps one more time and also follow instructions to troubleshoot: Jasper Report: KeyError: 'JAVA_HOME' - #2 by luisfmfernandes

Thanks for your reply, yashodhan.

I allready have this export in my /etc/profile, i had to do this for being able to install jasper_erpnext_report. (as discribed in the post you mentioned)

With the “env” command i can see:


…whitch seems to be the correct path.

But i dont understand why frappe cant make use of this environment variable.

BTW: I tried this on fresh (minimal) install of Debian Jessie and Ubuntu 14.04 with the same result by doing:

apt-get install openjdk-7-jdk
bench get-app jasper_erpnext_report
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
bench update --requirements
bench install-app jasper_erpnext_report

Hi @itsdave.

Has @yashodhan said try to call frappe from a fresh shell. Before that issue echo $JAVA_HOME in that shell. I know that you did env but some things still wrong.

I don’t know what to say to you. See what is wrong with your export.

The error you see is in pyjnius module when he try to create a jvm. He don’t find JAVA_HOME.

If you think everything is ok with your installation of java then try this:

Go to file jasper_erpnext_report/core/" and comment line 15 like this:

#from jasper_erpnext_report.jasper_reports.FrappeDataSource import _JasperCustomDataSource

and after line 134 add this line: from jasper_erpnext_report.jasper_reports.FrappeDataSource import _JasperCustomDataSource

You must have this in line 135 like this:

def _export_report(self, mparams, report_name, grid_data, sessionId, cur_doctype, custom, ids, jds_method):
from jasper_erpnext_report.jasper_reports.FrappeDataSource import _JasperCustomDataSource:

After this refresh frappe desk.

Any problem, let me know.

If this solution solve your problem let me know to make the change in original code.



Hello @luisfmfernandes,

finaly the tip for calling frappe from a shell lead me to the root of the problem.

I was running a production enviroment set up with “–setup-production” from the script .

As i had to learn, linux services strip most enviromental variables, so the export in /etc/profile was kind of useless for frappe. (but still necessary for “bench install-app jasper_erpnext_report”)

I ended up by adding the export to /etc/init.d/supervisor and was able to login again.

So i would like to thank you for guiding me in the right direction!

1 Like

PS: I thought i could now start over with making so shiny reports, but i ran into the issue described here:

I`m going to comment on this post.