ReferenceError: java is not defined

2,384 views
Skip to first unread message

Bhuvaneswari Sundararaman

unread,
Mar 31, 2012, 10:25:04 PM3/31/12
to mozilla-la...@googlegroups.com
Hi all


I am trying to call JAVA from lib/main.js file of my add on. A very simple line like
var myString= new java.lang.String("hello");
is throwing an error
ReferenceError: java is not defined
How can I call JAVA from addon? I am able to call any java class from a standlone js file, invoked via a html file. But when I call from the js file in the add-on it cannot find JAVA.

Am I missing something important?

I checked both on ubuntu 11.04 and windows 7. Same issue.

Please help.

Thanks.

Jeff Griffiths

unread,
Apr 1, 2012, 7:57:59 PM4/1/12
to mozilla-la...@googlegroups.com
main.js is not run in a codument context and therefore does not have
any of the web content apis available to it. For example,
typeof("java") should return "undefined".

If you want to write code that accesses DOM apis and other apis
usually found in web content code, the simplest approaches are:

1. attach a content script to an existing page - most convenient of
you are already interacting with web content anyway.

2. or, create a page-worker instance with an empty document and attach
your content script to it.

It's hard to tell what would be a better approach without knowing a
bit more about your use case. Why do you need to access browser / java
apis? I would have thought JS would be able to do most if not all you
would need.

Jeff

> --
> You received this message because you are subscribed to the Google Groups
> "mozilla-labs-jetpack" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mozilla-labs-jetpack/-/v7nfiTES85UJ.
> To post to this group, send email to
> mozilla-la...@googlegroups.com.
> To unsubscribe from this group, send email to
> mozilla-labs-jet...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mozilla-labs-jetpack?hl=en.

Reply all
Reply to author
Forward
0 new messages